//高精度加
#include <cstring>
#include <iostream>
using namespace std;
char aa[64], bb[64], cc[64];
int a[64], b[64], c[64];
int ans[64 * 3];
int add() {
int len_a = strlen(aa);
int len_b = strlen(bb);
int len_c = strlen(cc);
int tt = 0, i = 0, k = 0;
int len = max(max(len_a, len_b), len_c);
while (i < len) {
ans[k] = (a[i] + b[i] + c[i] + tt) % 10;
tt = (a[i] + b[i] + c[i] + tt) / 10;
k++;
i++;
}
if (tt != 0) {
ans[i++] = tt;
}
return i;
}
void init(char *src, int *des) {
int len = strlen(src);
for (int i = 0; i < len; i++) {
des[i] = src[len - i - 1] - '0';
}
}
int main() {
scanf("%s", aa);
init(aa, a);
scanf("%s", bb);
init(bb, b);
scanf("%s", cc);
init(cc, c);
int len_ans = add();
for (int i = len_ans - 1; i >= 0; i--) {
printf("%d", ans[i]);
}
system("pause");
return 0;
}
2_高精度加
最新推荐文章于 2024-08-25 23:11:21 发布