#include<iostream> #include<vector> #include<string> using namespace std; #define fio cin.tie(0);ios_base::sync_with_stdio(0); int ans[5003]; int a[5003]; int b[5003]; int main() { fio; string astr,bstr; cin>>astr>>bstr; int starter; if(astr.length()>bstr.length()){starter=astr.length();} else{starter=bstr.length();} for(int i=starter;i>starter-astr.length();i--) { a[i]=astr[astr.length()-1-(starter-i)]-48; } for(int i=starter;i>starter-bstr.length();i--) { b[i]=bstr[bstr.length()-1-(starter-i)]-48; } for(int i=starter;i>0;i--) { if(a[i]+b[i]+ans[i]<10) { ans[i]+=a[i]+b[i]; } else { ans[i]+=a[i]+b[i]-10; ans[i-1]=1; } } for(int i=0;i<4;i++) { } if(ans[0]==1){cout<<1;} for(int i=1;i<=starter;i++) { cout<<ans[i]; } 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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | #include<iostream> #include<vector> #include<string> using namespace std; #define fio cin.tie(0);ios_base::sync_with_stdio(0); int ans[5003]; int a[5003]; int b[5003]; int main() { fio; string astr,bstr; cin>>astr>>bstr; int starter; if(astr.length()>bstr.length()){starter=astr.length();} else{starter=bstr.length();} for(int i=starter;i>starter-astr.length();i--) { a[i]=astr[astr.length()-1-(starter-i)]-48; } for(int i=starter;i>starter-bstr.length();i--) { b[i]=bstr[bstr.length()-1-(starter-i)]-48; } for(int i=starter;i>0;i--) { if(a[i]+b[i]+ans[i]<10) { ans[i]+=a[i]+b[i]; } else { ans[i]+=a[i]+b[i]-10; ans[i-1]=1; } } for(int i=0;i<4;i++) { } if(ans[0]==1){cout<<1;} for(int i=1;i<=starter;i++) { cout<<ans[i]; } return 0; } |