AcWing 3596. a+b
原题链接
简单
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
const int N = 1e6+10;
int t,n,m,k,l,r,op,x,y;
int f[N];
bool flag;
string s1,s2,s3;
//int dp[N][N];
void solve(){
while(cin>>s1>>s2){
int siz1 = s1.size();
int siz2 = s2.size();
int k = max(siz1,siz2);
int add = 0;
int carry = 0;
s3.resize(k);
while(siz1>0||siz2>0){
add = carry + ((siz1>0)?(s1[siz1-1]-'0'):0) + ((siz2>0)?(s2[siz2-1]-'0'):0);
carry = add/10;
add%=10;
s3[k-1] = add+'0';
siz1--,siz2--,k--;
}
if(carry)s3.insert(s3.begin(),carry+'0');
cout<<s3<<"\n";
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
return 0;
}