版权声明:转载于[email protected]的博客 https://blog.csdn.net/nuoyanli/article/details/88901084
- 问题描述
- 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
参考代码:
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<map>
#include<set>
using namespace std;
#define N 10005
string a,b;
int A[N],B[N],C[N];
void init()
{
memset(A,0,sizeof(A));
memset(B,0,sizeof(B));
memset(C,0,sizeof(C));
int j=0;
for(int i=a.size()-1; i>=0; i--)
A[j++]=a[i]-'0';
j=0;
for(int i=b.size()-1; i>=0; i--)
B[j++]=b[i]-'0';
}
int main()
{
while(cin>>a>>b)
{
init();
int len=max(a.size(),b.size());
int dell=0;
for(int i=0; i<len; i++)
{
int temp=A[i]+B[i]+dell;
dell=temp/10;
C[i]=temp%10;
}
if(dell)
C[len++]++;
for(int i=len-1; i>=0; i--)
cout<<C[i];
cout<<endl;
}
return 0;
}
另外附上其他大数操作:
大数减法:
大数乘法:
大数除法:
大数取余: