Pagini recente » Istoria paginii utilizator/melniciucilie | Cod sursa (job #2210618) | Cod sursa (job #2839348) | Cod sursa (job #1852569) | Cod sursa (job #1098145)
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("adunare.in");
ofstream fout("adunare.out");
const int base= 10000;
const int cmax= 10;
void h_write( vector <int> &x ) {
fout<<x.back();
for ( int i= (int)x.size()-2; i>=0; --i ) {
if ( x[i]<10 ) {
fout<<"000";
} else if ( x[i]<100 ) {
fout<<"00";
} else if ( x[i]<1000 ) {
fout<<"0";
}
fout<<x[i];
}
fout<<"\n";
}
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>=(int)x.size() ) {
x.push_back(0);
}
if ( i<(int)y.size() ) {
x[i]+= y[i];
}
x[i]+= t;
t= x[i]/base;
x[i]%= base;
}
}
void h_turn( int &a, vector <int> &x ) {
while ( a!=0 ) {
x.push_back(a%base);
a/= base;
}
}
int main( ) {
int a, b;
fin>>a>>b;
vector <int> x, y;
h_turn( a, x ), h_turn(b, y );
hh_add( x, y );
h_write(x);
return 0;
}