#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
const int N = 5001;
void przedluz(string& S){
string zera="";
for(int i=0; i<N-S.size(); i++)
zera+="0";
S = zera+S;
}
string dodaj(string& A, string& B){
int reszta = 0;
string W = "";
for(int i=N-1; i>=0; i--){
reszta += A[i] + B[i] - 2*'0';
W.push_back(reszta%10 + '0');
reszta /= 10;
}
while(W.back()=='0'){
W.pop_back();
}
reverse(W.begin(), W.end());
return W;
}
int main(){
string A,B;
cin >> A >> B;
przedluz(A);
przedluz(B);
cout << dodaj(A,B);
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | #include <iostream> #include <string> #include <algorithm> using namespace std; const int N = 5001; void przedluz(string& S){ string zera=""; for(int i=0; i<N-S.size(); i++) zera+="0"; S = zera+S; } string dodaj(string& A, string& B){ int reszta = 0; string W = ""; for(int i=N-1; i>=0; i--){ reszta += A[i] + B[i] - 2*'0'; W.push_back(reszta%10 + '0'); reszta /= 10; } while(W.back()=='0'){ W.pop_back(); } reverse(W.begin(), W.end()); return W; } int main(){ string A,B; cin >> A >> B; przedluz(A); przedluz(B); cout << dodaj(A,B); return 0; } |
English