#include<bits/stdc++.h> using namespace std; using ll=long long; string s1,s2; vector<short>res; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin>>s1>>s2; res.resize(max(s1.size(),s2.size())+1); reverse(s1.begin(),s1.end()); reverse(s2.begin(),s2.end()); for(int i=0;i<s1.size();++i) res[i]+=s1[i]-48; for(int i=0;i<s2.size();++i) res[i]+=s2[i]-48; int carry=0; for(int i=0;i<res.size();++i){ res[i]+=carry; carry=res[i]/10; res[i]%=10; } reverse(res.begin(),res.end()); int i=0; while(res[i]==0) ++i; for(;i<res.size();++i) cout<<res[i]; }
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 | #include<bits/stdc++.h> using namespace std; using ll=long long; string s1,s2; vector<short>res; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin>>s1>>s2; res.resize(max(s1.size(),s2.size())+1); reverse(s1.begin(),s1.end()); reverse(s2.begin(),s2.end()); for(int i=0;i<s1.size();++i) res[i]+=s1[i]-48; for(int i=0;i<s2.size();++i) res[i]+=s2[i]-48; int carry=0; for(int i=0;i<res.size();++i){ res[i]+=carry; carry=res[i]/10; res[i]%=10; } reverse(res.begin(),res.end()); int i=0; while(res[i]==0) ++i; for(;i<res.size();++i) cout<<res[i]; } |