#include <bits/stdc++.h> using namespace std; int main() { string s,w; cin>>s>>w; reverse(s.begin(),s.end()); reverse(w.begin(),w.end()); int a[5007],b[5007]; int c[5007]; for(int i=0;i<5007;i++) { if(i < s.size()) a[i] = s[i]-'0'; else a[i] = 0; if(i < w.size()) b[i] = w[i]-'0'; else b[i]=0; } for(int i=0;i<5007;i++) c[i]=0; for(int i=0;i<5006;i++) { c[i]+=a[i]+b[i]; c[i+1]+=c[i]/10; c[i]%=10; } int i=5006; while(i>=0 && c[i]==0) i--; if(i==-1) { cout<<"0\n"; return 0; } for(;i>=0;i--) { cout<<c[i]; } cout<<"\n"; 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 | #include <bits/stdc++.h> using namespace std; int main() { string s,w; cin>>s>>w; reverse(s.begin(),s.end()); reverse(w.begin(),w.end()); int a[5007],b[5007]; int c[5007]; for(int i=0;i<5007;i++) { if(i < s.size()) a[i] = s[i]-'0'; else a[i] = 0; if(i < w.size()) b[i] = w[i]-'0'; else b[i]=0; } for(int i=0;i<5007;i++) c[i]=0; for(int i=0;i<5006;i++) { c[i]+=a[i]+b[i]; c[i+1]+=c[i]/10; c[i]%=10; } int i=5006; while(i>=0 && c[i]==0) i--; if(i==-1) { cout<<"0\n"; return 0; } for(;i>=0;i--) { cout<<c[i]; } cout<<"\n"; return 0; } |