Bored Three -God(NBUT) 1228

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值