链接:https://ac.nowcoder.com/acm/contest/19859/F
来源:牛客网
题目描述
There are many difficulties in today’s contest, but this is definitely not one of them.
Because I want you to do it, the classic A+B.
输入描述:
First line an Integer N means n test cases.
Next 2N lines representing 2N groups of different Integers.
N<50.
THE LENGTH of every Integer will less than 5000.
All Integers will be greater than 0.
Some cases may have leading zero.
输出描述:
One line for each test cases reprecenting the answer of A+B.
Do not putout leading zero
示例1
输入
1
100000000000000
100000000000000
输出
200000000000000
#include<stdio.h>
#include<string.h>
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
char s1[5100],s2[5100];//A和B很大,所以用字符串形式输入
scanf("%s",s1);
scanf("%s",s2);
int i,j,k;
int a1[5100]={0},a2[5100]={0};
int len1=strlen(s1);
int len2=strlen(s2);
for(i=len1-1,j=0;i>=0;i--,j++)
a1[j]=s1[i]-'0';//再把每一位倒序存入数组中,方便相加
for(i=len2-1,j=0;i>=0;i--,j++)
a2[j]=s2[i]-'0';
int a3[5100]={0};
for(i=0;i<=len1+len2;i++)
{
a3[i]=a1[i]+a2[i];//两个数组每一位相加存入新数组中
}
for(i=0;i<=len1+len2;i++)
{//处理逢10进一的情况
if(a3[i]>=10)
{
a3[i]%=10;
a3[i+1]++;
}
}
int flag=0;
for(i=len1+len2;i>=0;i--)
{
if(a3[i]!=0)
{//确定数组的首位
flag=1;
}
if(flag)//首位后的数都要输出
printf("%d",a3[i]);
}
printf("\n");
}
return 0;
}