AcWing 1. A + B
原题链接
简单
作者:
lin_king
,
2025-01-18 12:32:37
,
所有人可见
,
阅读 3
样例
#include <iostream>
#include <vector>
using namespace std;
vector<int> C;
void add(auto A,auto B){
int t = 0;
for(int i = 0;i<=A.size()||i<=B.size();i++)
{
C.push_back((A[i] + B[i] + t)%10);
if((A[i] + B[i]+t)>=10) t = 1;
else t =0;
}
//-0
for(int i = C.size()-1;i > 0 && C[i] == 0;i--) C.pop_back();
}
int main(){
string a,b;
cin>>a>>b;
vector<int> A,B;
for(int i =a.size()-1;i>=0;i--) A.push_back(a[i]-'0');
for(int i =b.size()-1;i>=0;i--) B.push_back(b[i]-'0');
//cs
// for(int i =A.size()-1;i>=0;i--) cout<<A[i]<<endl;
add(A,B);
for(int i =C.size()-1;i>=0;i--) cout<<C[i];
return 0;
}