#include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string a; string b; cin>>a>>b; while(a.size()<b.size()){ a='0'+a; } while(a.size()>b.size()){ b='0'+b; } string wap=""; int dod=0; for(int i=a.size()-1;i>=0;i--){ int al = a[i]-'0'; int bl = b[i]-'0'; int wyn = al+bl+dod; dod = wyn/10; wyn = wyn%10; char f = wyn+'0'; wap = f + wap; } if(dod>0){ char h = dod+'0'; wap=h+wap; } cout<<wap<<"\n"; }
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 | #include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string a; string b; cin>>a>>b; while(a.size()<b.size()){ a='0'+a; } while(a.size()>b.size()){ b='0'+b; } string wap=""; int dod=0; for(int i=a.size()-1;i>=0;i--){ int al = a[i]-'0'; int bl = b[i]-'0'; int wyn = al+bl+dod; dod = wyn/10; wyn = wyn%10; char f = wyn+'0'; wap = f + wap; } if(dod>0){ char h = dod+'0'; wap=h+wap; } cout<<wap<<"\n"; } |