-
[1228] Bored Three-God
- 时间限制: 1000 ms 内存限制: 65535 K
- 问题描述
- 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".
- 输入
-
There are muti-case
For each case, there are two integers, n, m (0 < n, m < 10^10000). - 输出
-
Calculate two integers' sum
- 样例输入
-
1 1 2 3 10000 100000
- 样例输出
-
2 5 110000
- 提示
-
无
- 来源
-
Three-God
- 操作
题目大意:大数加法!!
思路:超级简单,但是要注意如果输入有前导0,则输出也要有前导0(说实话,第一次见到这么恶心的大数,还带前导0的)
代码:
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<cmath>
#include<string>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll unsigned long long
#define inf 0x3f3f3f3
#define esp 1e-8
#define bug {printf("mmp\n");}
#define mm(a,b) memset(a,b,sizeof(a))
#define T() int test,q=1;scanf("%d",&test); while(test--)
const int maxn=2e6+100;
const double pi=acos(-1.0);
const int N=2e6;
const int mod=1e9+7;
char s1[N],s2[N];
int a[N],b[N],c[N];
void add()
{
mm(a,0);
mm(b,0);
mm(c,0);
int l1=strlen(s1);
int l2=strlen(s2);
int lm=max(l1,l2);
int la=0,lb=0;
for(int i=l1-1;i>=0;i--)
a[la++]=s1[i]-'0';
for(int i=l2-1;i>=0;i--)
b[lb++]=s2[i]-'0';
for(int i=0;i<lm;i++)
{
c[i]+=a[i]+b[i];
c[i+1]+=c[i]/10;
c[i]%=10;
}
if(c[lm])
printf("%d",c[lm]);
for(int i=lm-1;i>=0;i--)
printf("%d",c[i]);
printf("\n");
}
int main()
{
while(scanf("%s %s",s1,s2)!=EOF)
{
add();
}
return 0;
}