题目为HDU 1002
链接:http://acm.hdu.edu.cn/showpro...
题目意思即是有两个超级大的数相加,求和
具体方法就是模拟两个数相加求和就好
AC code
请输入代码#include <stdio.h>
#include <string.h>
char a[1010];//数字a
char b[1010];//数字b
int suma[1010]; //存储数字a每一位的数组
int sumb[1010]; //存储数字b每一位的数组
int main()
{
int T;
scanf("%d",&T);
int Case=0;
while(T--)
{
scanf("%s%s",a,b);
memset(suma,0,sizeof(suma));**//先把suma 和sumb 两个初始化为0;**
memset(sumb,0,sizeof(sumb));
int i,len=0;
int lena=strlen(a);
int lenb=strlen(b);
//**进行数组存储**
for(i=lena-1; i>=0; i--)
suma[len++]=a[i]-'0';
len=0;
for(i=lenb-1; i>=0; i--)
sumb[len++]=b[i]-'0';
//下面就是模仿相加求和
/*例如
99999999 00999
+11111111 + 11001
————————— ————————
100000000 12000
就是大于10下一位进1;
suma[i]-=10;
suma[i+1]++;
*/
for(i=0; i<1002; i++)
{
suma[i]=suma[i]+sumb[i];
if(suma[i]>=10)
{
suma[i]-=10;
suma[i+1]++;
}
}
Case++;
if(Case>1) printf("\n");
printf("Case %d:\n",Case);
printf("%s + %s = ",a,b);
i=1001;
while(suma[i]==0)
i--;
for(;i>=0;i--)
printf("%d",suma[i]);
printf("\n");
}
return 0;
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。