链接:
https://www.nowcoder.com/acm/contest/125/C
来源:牛客网
来源:牛客网
题目描述
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
#include<bits/stdc++.h>
using namespace std;
char s1[5005],s2[5005];
int a[5005],b[5005],c[5005]={0};
int main()
{
int t,pos;
cin>>t;
while(t--)
{
memset(c,0,sizeof(c));
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
cin>>s1>>s2;
int n=strlen(s1);
int m=strlen(s2);
int l=m>n?m:n;
int i,j;
for(i=n-1;i>=0;i--)
{
a[n-i-1]=s1[i]-'0';
}
for(i=m-1;i>=0;i--)
{
b[m-i-1]=s2[i]-'0';
}
for(j=0;j<=l;j++)
{
c[j]+=a[j]+b[j];
if(c[j]>9)
{
c[j]-=10;
c[j+1]++;
}
}
while(l--)
{
if(c[l]!=0)
{
pos=l;
break;
}
}
for(i=pos;i>=0;i--)
cout<<c[i];
cout<<endl;
}
}