#include<bits/stdc++.h>
using namespace std;
int toInt(char c){
return int(c) - 48;
}
char toChar(int c) {
return char(48 + c);
}
int main(){
string a,b; cin >> a >> b;
while(a.size() != b.size()){
if(a.size() < b.size()) a = "0" + a;
else b = "0" + b;
}
int przen = 0;
int pod = 10;
string res = "";
for(int i = a.size() - 1; i >= 0; i--){
int suma = przen + toInt(a[i]) + toInt(b[i]);
res = toChar(suma%pod) + res;
przen = suma/pod;
}
if(przen != 0) res = toChar(przen) + res;
cout << res;
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 | #include<bits/stdc++.h> using namespace std; int toInt(char c){ return int(c) - 48; } char toChar(int c) { return char(48 + c); } int main(){ string a,b; cin >> a >> b; while(a.size() != b.size()){ if(a.size() < b.size()) a = "0" + a; else b = "0" + b; } int przen = 0; int pod = 10; string res = ""; for(int i = a.size() - 1; i >= 0; i--){ int suma = przen + toInt(a[i]) + toInt(b[i]); res = toChar(suma%pod) + res; przen = suma/pod; } if(przen != 0) res = toChar(przen) + res; cout << res; return 0; } |
English