E-牛牛的加法
- 模拟加法运算,需要进1的时候,不进位
- 注意去掉前导0
代码如下:
#include<bits/stdc++.h>
using namespace std;
#define mm(a,x) memset(a,x,sizeof a)
#define mk make_pair
#define ll long long
#define pii pair<int,int>
#define inf 0x3f3f3f3f
#define lowbit(x) (x) & (-x)
string a,b;
vector<int > A,B;
vector<int > C;
int main() {
cin >> 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');
int t = 0;
for(int i = 0; i < A.size() || i < B.size(); i ++ ){
if(i < A.size()) t += A[i];
if(i < B.size()) t += B[i];
C.push_back(t%10);
t = 0;
}
while(C.size() > 1 && C.back() == 0) C.pop_back();
for(int i = C.size() - 1; i >= 0; i -- ){
cout<<C[i];
}
return 0;
}