Pagini recente » Cod sursa (job #2124712) | Cod sursa (job #1013964) | Cod sursa (job #1298001) | Cod sursa (job #285555) | Cod sursa (job #1098147)
#include<fstream>
#include<vector>
using namespace std;
ifstream fin( "adunare.in" );
ofstream fout( "adunare.out" );
const int base = 10;
vector <int> x;
vector <int> y;
void h_from_n( int n, vector <int> &h ) {
while ( n != 0 ) {
h.push_back( n % 10 );
n /= 10;
}
}
void hh_add ( vector <int> &x, vector <int> &y ) {
int t = 0;
for( int i = 0; i<(int)x.size() || i<(int)y.size() || t!=0; ++ i ) {
if ( i == x.size() ) {
x.push_back( 0 );
}
x[i] = x[i] + y[i] + t;
if ( x[i] >= base ) {
t = 1;
x[i] -= base;
} else
t = 0;
}
}
void h_write( vector <int> &a ) {
for( int i = (int)a.size() - 1; i >= 0; -- i )
fout<<x[i];
}
int main()
{
int a, b;
fin>>a>>b;
h_from_n( a, x );
h_from_n( b, y );
hh_add( x, y );
h_write( x );
fout<<'\n';
fin.close();
fout.close();
return 0;
}