大数乘
Time Limit:5000MS Memory Limit:32768KDescription:
给定一些大数,请计算其积。Input:
输入数据中含有一些整数对(对数≤1000),若某对整数(整数位数≤200)的值为0 0,则表示输入结束。
Output:
每对整数对应一个乘法计算结果,输出该结果,每个结果输出完后应回车。
Sample Input:
2 312 340 0
Sample Output:
6408
1 /* 功能Function Description: 大数相乘 2 开发环境Environment: DEV C++ 4.9.9.1 3 技术特点Technique: 4 版本Version: 5 作者Author: 可笑痴狂 6 日期Date: 20120725 7 备注Notes: 8 */ 9 #include10 #include 11 #define MAX 21012 13 int main()14 {15 char s1[MAX],s2[MAX];16 int i,j,len1,len2;17 int a[MAX],b[MAX],res[MAX*2];18 while(scanf("%s%s",s1,s2))19 {20 memset(res,0,sizeof(res));21 if(strcmp(s1,"0")==0&&strcmp(s2,"0")==0)22 break;23 len1=strlen(s1);24 len2=strlen(s2);25 for(i=len1-1,j=0;i>=0;--i)26 a[j++]=s1[i]-'0';27 for(i=len2-1,j=0;i>=0;--i)28 b[j++]=s2[i]-'0';29 for(i=0;i =10)35 {36 res[i+1]+=res[i]/10;37 res[i]%=10;38 }39 }40 while(i>=0&&res[i]==0)41 --i;42 if(i>=0)43 {44 for(;i>=0;--i)45 printf("%d",res[i]);46 printf("\n");47 }48 else49 printf("0\n");50 }51 return 0;52 }