hdu 1047 Integer Inquiry 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1047
大数
题目分析:字符处理。
code:
#include<stdio.h>
#include<string.h>
int main()
{
int t,a[10000],i,maxlen,flag;
char c[10000];
scanf("%d",&t);
while(t--)
{
flag=maxlen=0;
memset(a,0,sizeof(a));
while(scanf("%s",c)!=EOF&&c[0]!='0')
{
maxlen=maxlen>strlen(c)?maxlen:strlen(c);
for(i=0;i<strlen(c);i++)
{
a[i]+=c[strlen(c)-1-i]-'0';
a[i+1]+=a[i]/10;
a[i]%=10;
}
flag=1;
}
if(!flag)printf("0");else
{if(a[maxlen])printf("%d",a[maxlen]);
for(i=maxlen-1;i>=0;i--)
{
printf("%d",a[i]);
}}
printf("\n");
if(t)printf("\n");
}
return 0;
}PS:人穷志短了,老水,居然还WA了两次……

本文介绍了一道经典的HDU 1047 IntegerInquiry题目,通过字符处理的方式实现大数加法运算,解决了输入多个大整数并输出它们的和的问题。
1129

被折叠的 条评论
为什么被折叠?



