Uva 10106 - Product
Product |
The Problem
The problem is to multiply two integers X, Y. (0<=X,Y<10250)
The Input
The input will consist of a set of pairs of lines. Each line in pair contains one multiplyer.
The Output
For each input pair of lines the output line should consist one integer the product.
Sample Input
12 12 2 222222222222222222222222
Sample Output
144 444444444444444444444444
#include<stdio.h> #include<string.h> int main() { int sum[502], i, j, t, loop, jlen, ilen, temp, e; char inter[251], jnter[251]; memset(sum, 0, sizeof(sum)); memset(inter, 0, sizeof(inter)); memset(jnter, 0, sizeof(jnter)); while(scanf("%s", inter) != EOF) { getchar(); scanf("%s", jnter); e = 0; ilen = strlen(inter); jlen = strlen(jnter); for(j=jlen-1; j>=0; --j) { loop = jlen-1-j; for(i=ilen-1; i>=0; --i, ++loop) { temp = sum[loop]; sum[loop] = (e+sum[loop]+(inter[i]-'0')*(jnter[j]-'0'))%10; e = (e+temp+(inter[i]-'0')*(jnter[j]-'0'))/10; } for(t=loop; t<502 && e; ++t) { temp = sum[t]; sum[t] = (e + sum[t])%10; e = (e + temp)/10; } } for(i=501, temp = 0; i>=0; --i) { if(sum[i] != 0) { temp = 1; printf("%d", sum[i]); } else if(temp == 1) { printf("%d", sum[i]); } } if(temp == 0)printf("0"); printf("\n"); memset(sum, 0, sizeof(sum)); memset(inter, 0, sizeof(inter)); memset(jnter, 0, sizeof(jnter)); } return 0; }
解题报告:
两个大数相乘,无可厚非按照手工计算的方法进行,知道了两个大数相加这题也就容易了。
![物役记](https://s2.ax1x.com/2019/05/26/VE5YD0.jpg)
更多内容请关注个人微信公众号 物役记 (微信号:materialchains)
作者:雪影蓝枫
本文版权归作者和博客园共有,欢迎转载,未经作者同意须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。