J - Bored Three-God
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
无
题意:
大数 A+B。
思路:
不过这个输入可能有前导 0,但是输出时前导 0不能省略。把bin神的大数板子中 mod改为 10即可
代码:
#include<queue>
#include<iostream>
#include<string.h>
#include<cstdio>
#define mset(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
const int maxn=1e5+10;
struct bigNum
{
const static int mod=10;
const static int DLEN=1;
int a[maxn],len;
bigNum()
{
mset(a,0),len=0;
}
bigNum(const char s[])
{
mset(a,0);
int L=strlen(s);
len=L/DLEN;
if(L%DLEN) len++;
int index=0;
for(int i=L-1;i>=0;i-=DLEN){
int t=0;
int k=i-DLEN+1;;
if(k<0) k=0;
for(int j=k;j<=i;++j)
t=t*10+s[j]-'0';
a[index++]=t;
}
}
bigNum operator +(const bigNum &b)const
{
bigNum res;
res.len=max(len,b.len);
for(int i=0;i<res.len;++i)
res.a[i]=0;
for(int i=0;i<res.len;i++){
res.a[i]+=((i<len)?a[i]:0)+((i<b.len)?b.a[i]:0);
res.a[i+1]+=res.a[i]/mod;
res.a[i]%=mod;
}
if(res.a[res.len]>0) res.len++;
return res;
}
void print(){
printf("%d",a[len-1]);
for(int i=len-2;i>=0;--i)
printf("%d",a[i]);
puts("");
}
};
char sa[maxn],sb[maxn];
int main()
{
bigNum res;
while(~scanf("%s %s",sa,sb)){
bigNum aa(sa);
bigNum bb(sb);
(aa+bb).print();
}
return 0;
}