J - Bored Three-God (NBUT 1228)
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
Hint
无
题目翻译:
无聊的三人——上帝——得到了另一个无聊的问题。
这个问题是请你再加两个大个子,请帮助他,当你解决这个问题的时候你就可以了
对三个上帝说:“哦,请给我一个难解的,这个太简单了。”
输入
有muti-case
对于每种情况,都有两个整数,n, m (0 < n, m < 10^10000)。
输出
计算两个整数的和
样例输入
1 1
2 3
10000 100000
样例输出
2
5
110000
提示
无
思路:
这道题是大数板子,注意前导0,输入输出都有前导0.
AC代码:
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
using namespace std;
int x[10005],y[10005],z[10005];
char a[10005],b[10005];
int main()
{
while(~scanf("%s%s",a,b))
{
memset(z,0,sizeof(z));
memset(x,0,sizeof(x));
memset(y,0,sizeof(y));
int aa=strlen(a);
int bb=strlen(b);
int p=0;
for(int i=aa-1; i>=0; i--)x[p++]=a[i]-'0';
p=0;
for(int i=bb-1; i>=0; i--)y[p++]=b[i]-'0';
int d=0;
p=max(aa,bb);
for(int i=0;i<=p; i++)
{
int s=x[i]+y[i]+d;
z[i]=s%10;
d=s/10;
}
if(z[p])printf("%d",z[p]);
for(int i=p-1; i>=0; i--)
printf("%d",z[i]);
printf("\n");
}
}