J - Bored Three-God --输出前导0

博客讲述了如何处理一道要求保留前导0的大数加法问题。题目要求计算两个大数的和,输入可能包含前导0,输出时必须保持与输入相同的位数。由于不寻常的条件,导致了计算的复杂性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

大数加法,输入两个数,求和。

一道有毒的题。输入的时候有前导0,输出的时候不能删。。。正常情况下我是不会考虑这个的,,活该我wa到自闭。

所以这个大数加法是没有删0操作的,全程保留所有数,卡着输入的数的长度算。

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char a[11000],b[11000],c[11000],d[11000],hh[11000];
int main()
{
    while(scanf("%s %s",a,b)!=EOF)
    {
        int x,y,j;
        x=strlen(a);
        y=strlen(b);
        memset(c,'0',sizeof(c));
        memset(d,'0',sizeof(d));
        memset(hh,'0',sizeof(hh));
        for(int i=0; i<x; i++)
            c[i]=a[x-i-1];
        for(int i=0; i<y; i++)
            d[i]=b[y-i-1];
        int e=0;
        for(int i=0; i<max(x,y); i++)
        {
            hh[i]=(c[i]-'0')+(d[i]-'0')+e+'0';
            e=(hh[i]-'0')/10;
            hh[i]=(hh[i]-'0')%10+'0';
        }
        if(e!=0)
        {
             j=max(x,y); hh[j]=e+'0';
        }
        else
            j=max(x,y)-1;
        for(int i=j; i>=0; i--)
            printf("%c",hh[i]);
        printf("\n");
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值