求助:A+B Problem高精只能拿60分

题目总版

the ans: ```cpp #include <iostream> #include <cstdio> using namespace std; int main() { int a,b; cin >> a >> b; cout << a+b << endl; return 0; } ``` 你的算法有问题
by Enoch2013 @ 2024-04-27 15:50:08


但是你给的算法不能算超过int范围的数啊
by wstucn @ 2024-04-27 15:52:57


@[Enoch2013](/user/1069719) 准确来说也叫一种答案吧(
by wstucn @ 2024-04-27 15:55:05


第三个检测点的输入:1111111111111111111111111 9999999999999999999999999999999999 我的输出: 10000000011111111111111111111111110
by wstucn @ 2024-04-27 16:00:38


@[wstucn](/user/1101485) 试试这个 ```cpp #include <bits/stdc++.h> using namespace std; char s[1001]; int a[1001], b[1001], c[1001]; int la, lb, lc; int main () { scanf("%s", s + 1); la = strlen(s + 1); for (int i = 1; i <= la; i++) { a[i] = s[la - i + 1] - '0'; } scanf("%s", s + 1); lb = strlen(s + 1); for (int i = 1; i <= lb; i++) { b[i] = s[lb - i + 1] - '0'; } if (la > lb) { lc = la; } else { lc = lb; } for (int i = 1; i <= 101; i++) { c[i] = 0; } for (int i = 1; i <= lc; i++) { c[i] = a[i] + b[i] + c[i]; c[i + 1] = c[i] / 10; c[i] = c[i] % 10; } if(c[lc+1] > 0) lc++; for(int i=lc;i>=1;i--){ cout << c[i]; } }
by sunningli @ 2024-04-27 20:43:47


让我研究一下,谢谢了
by wstucn @ 2024-05-01 17:38:41


|