Description
The bored Three-God get another boring question.
This problem is ask you plus two big nubmer, please help him, when you solve this problem you can
speak to Three-God,“Oh, Please give me a diffculte one, this one is too easy”.
Input
There are muti-case
For each case, there are two integers, n, m (0 < n, m < 10^10000).
Output
Calculate two integers’ sum
Sample Input
1 1
2 3
10000 100000
Sample Output
2
5
110000
很明显,这是一道大数问题,但是此题比较坑的地方就是需要考虑前导0,比如01+01答案是02而不是2,其它的就是用大数加法的思路解决就行了,代码如下。
#include <iostream>
#include<string.h>
#include<algorithm>
#include<stdio.h>
using namespace std;
char v[100005],s[100005];
int x[100005],y[100005],z[100005];
int main()
{
while(scanf("%s",v)!=EOF)
{
memset(x,0,sizeof(x));
memset(y,0,sizeof(y));
memset(z,0,sizeof(z));
scanf("%s",s);
int a=strlen(v),b=strlen(s);
int c=max(a,b);
for(int i=a-1,j=0;i>=0;i--)
{
x[j++]=v[i]-'0';
}
for(int i=b-1,j=0;i>=0;i--)
{
y[j++]=s[i]-'0';
}
for(int i=0;i<c;i++)
{
z[i]+=x[i]+y[i];
if(z[i]>=10)
{
z[i+1]=z[i]/10;
z[i]=z[i]%10;
}
}
if(z[c]!=0)
{
printf("%d",z[c]);
}
for(int i=c-1;i>=0;i--)
{
printf("%d",z[i]);
}
printf("\n");
}
return 0;
}