[1228] Bored Three-God

  • [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;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值