UVA 10106-Product(大数乘法)
发布时间:2020-12-14 02:53:47 所属栏目:大数据 来源:网络整理
导读:Product Time Limit: 3000 MS????? Memory Limit: 0 KB????? 64bit IO Format: %lld %llu Submit ? Status Description ?Product ? The Problem The problem is to multiply two integers X,Y. ( 0=X,Y10 250 ) The Input The input will consist of a set o
Product
Time Limit:3000MS?????Memory Limit:0KB?????64bit IO Format:%lld & %llu
Description
The ProblemThe problem is to multiply two integers X,Y. (0<=X,Y<10250) The InputThe input will consist of a set of pairs of lines. Each line in pair contains one multiplyer. The OutputFor each input pair of lines the output line should consist one integer the product. Sample Input12 12 2 222222222222222222222222 Sample Output144 444444444444444444444444 注意当为0的情况,一开始忽略了这种情况。当任一个为0的时候别忘了输出0 #include<stdio.h> #include<string.h> #include<stdlib.h> char str1[1010],str2[1010]; char a[1010],b[1010],sum[1010]; int main() { int len1,len2; int i,j; while (~scanf("%s",str1)) { memset(a,sizeof(a)); memset(b,sizeof(b)); memset(sum,sizeof(sum)); len1= strlen(str1); for (i=len1-1;i>=0;i--) a[len1-i-1]=str1[i]-'0'; scanf("%s",str2); len2=strlen(str2); for (i=len2-1;i>=0;i--) b[len2-i-1]=str2[i]-'0'; for (i=0;i<len1;i++) { for(j=0;j<len2;j++) sum[i+j]+=a[i]*b[j]; for (j=0;j<1010;j++) if (sum[j]>=10) { sum[j+1]+=sum[j]/10; sum[j]%=10; } } int flag=0; for(i=1010;i>=0;i--) { if(flag||sum[i]) { flag=1; printf("%d",sum[i]); } } if(!flag) printf("0"); printf("n"); } return 0; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |