- 分享
为啥高精度不行?(bzoj#P3767. A+B Problem 加强版)
- @ 2025-11-23 19:11:32
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N = 210;
int a[N], b[N], ans[N];
signed main(){
string x, y;
cin >> x >> y;
reverse(x.begin(), x.end());
reverse(y.begin(), y.end());
for(int i = 0; i < x.size(); i ++) a[i] = x[i] - '0';
for(int i = 0; i < y.size(); i ++) b[i] = y[i] - '0';
int len = max(x.size(), y.size());
for(int i = 0; i < len; i ++){
ans[i] += a[i] + b[i];
ans[i + 1] += ans[i] / 10;
ans[i] %= 10;
}
while(ans[len] == 0 && len > 0) len --;
for(int i = len; i >= 0; i --) cout << ans[i];
return 0;
}
0 条评论
目前还没有评论...