高精加 题解
2023-09-06 22:19:09
发布于:广东
1阅读
0回复
0点赞
大家应该都理解高精加的思路吧
既然理解了,那我就不做过多解释了
AC代码
#include <bits/stdc++.h>
using namespace std;
const int MAX = 5000;
int toPlus(int a[], int b[], int la, int lb) {
int i, len;
if(la > lb)
len = la;
else
len = lb;
for(i = 0; i < len; i++){
a[i] = a[i] + b[i];
a[i+1] = a[i+1] + a[i] / 10;
a[i] = a[i] % 10;
}
if(a[len] != 0)
len++;
return len;
}
int main(int argc, const char * argv[]) {
string str1, str2;
int la, lb, i;
int a[MAX], b[MAX];
while(cin >> str1 >> str2) {
la = (int)str1.size();
lb = (int)str2.size();
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
for(i = 0; i < la; i++)
a[la-i-1] = str1[i] - '0';
for(i = 0; i < lb; i++)
b[lb-i-1] = str2[i] - '0';
la = toPlus(a, b, la, lb);
for(i = 0; i < la; i++)
cout << a[la - i - 1];
cout << endl;
}
return 0;
}
这里空空如也
有帮助,赞一个