J - Bored Three-God (NBUT 1228)

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");
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值