这道题的第一个输入数据是123、123;输出数据是246。我在自己的编译器上运行结果是正确的。但到了洛谷上就WA了。 不知道咋错的,求助大佬。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string.h>
#include<map>
#include<algorithm>
using namespace std;
//a=1576492,b=6435412123
#define size 10000
int main()
{
char a[size], b[size];
int a1[size], b1[size], c1[size];
memset(a1, 0, sizeof(a1));
memset(b1, 0, sizeof(b1));
memset(c1, 0, sizeof(c1));
gets(a);
gets(b);
int len1 = strlen(a);
int len2 = strlen(b);
int max1 = max(len1, len2);
int x = 0;
for (int i = 0; i < len1; i++)//将a数组里的数字首尾互换
a1[i] = a[len1 - i - 1] - 48;
for (int i = 0; i < len2; i++)//将b数组里的数字首尾互换
b1[i] = b[len2 - i - 1] - 48;
for (int i = 0; i < max1; i++)
{
if (a1[i] + b1[i] + c1[i] < 10) //不需要进位时的情况
c1[i] = a1[i] + b1[i] + c1[i];
else //需要进位时的情况
{
if (i == max1-1)
{
x = 1;
c1[i] = a1[i] + b1[i] +c1[i] - 10;
}
else
{
c1[i + 1] += 1;
c1[i] = a1[i] + b1[i] +c1[i] - 10;
}
}
}
if (x != 0)
cout << x;
for (int i = max1 - 1; i >= 0; i--)
cout << c1[i];
return 0;
}