J - Bored Three-God --输出前导0
作者:互联网
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);
int ha=0,h=0;
while(a[ha]=='0')
ha++;
while(b[h]=='0')
h++;
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");
}
}
标签:11000,int,God,memset,Three,include,hh,sizeof,Bored 来源: https://blog.csdn.net/qq_43644454/article/details/88895082