#include<bits/stdc++.h> using namespace std; string wyn=""; void dodaj(string a, string b) { int ile=0, pom; for(int i=a.size()-1; i>=0; i--) { pom=a[i]-'0' + b[i]-'0' + ile; ile=pom/10; pom=pom%10; wyn = (char)(pom+'0') + wyn;; } if(ile!=0) { wyn=(char)(ile+'0') + wyn; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string a, b; cin >> a >> b; if(a.size()<b.size()) { swap(a, b); } while(b.size()<a.size()) { b="0"+b; } dodaj(a, b); cout << wyn; }
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 | #include<bits/stdc++.h> using namespace std; string wyn=""; void dodaj(string a, string b) { int ile=0, pom; for(int i=a.size()-1; i>=0; i--) { pom=a[i]-'0' + b[i]-'0' + ile; ile=pom/10; pom=pom%10; wyn = (char)(pom+'0') + wyn;; } if(ile!=0) { wyn=(char)(ile+'0') + wyn; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string a, b; cin >> a >> b; if(a.size()<b.size()) { swap(a, b); } while(b.size()<a.size()) { b="0"+b; } dodaj(a, b); cout << wyn; } |