高精度加法,putchar(),getchar()比scanf(),printf()快。效率相差10多倍。
View Code
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
#define maxn 1000006
int f1[maxn], f2[maxn];
char ans[maxn];
int main()
{
//freopen("t.txt", "r", stdin);
int n;
scanf("%d", &n);
getchar();
for (int i = 0; i < n; i++)
{
f1[i] = getchar() - '0';
getchar();
f2[i] = getchar() - '0';
getchar();
}
int temp = 0;
for (int i = n - 1; i >= 0; i--)
{
ans[i] = ((f1[i] + f2[i] + temp) % 10) + '0';
temp = (f1[i] + f2[i] + temp) / 10;
}
for (int i = 0; i < n; i++)
putchar(ans[i]);
putchar('\n');
return 0;
}