Problem 1453 Bignum Arithmetic from http://acm.fzu.edu.cn/problem.php?pid=1453
2012-09-11 09:44
495 查看
![](http://acm.fzu.edu.cn/image/problem.gif)
Problem 1453 Bignum Arithmetic
Accept: 399 Submit: 1028
Time Limit: 1000 mSec Memory Limit : 32768 KB
![](http://acm.fzu.edu.cn/image/prodesc.gif)
Problem Description
In this problem, you will be concerned with integers with very large numbers of digits. You must write code which will repeatedly accept (until end of file) two lines each containing an unsigned integer, and output the product of the two input unsigned integers.The output must not contain any leading zeros.
You can assume that each integer will contain at most 80 digits. The input ends with an end of file.
![](http://acm.fzu.edu.cn/image/prodesc.gif)
Sample Input
03421298123
![](http://acm.fzu.edu.cn/image/prodesc.gif)
Sample Output
44391636#include <iostream> #include <cstdio> #include <string.h> using namespace std; int a[100]; int b[100]; char s1[100]; char s2[100]; int c[200]; int lena, lenb, i, j, len; void multi(){ memset(c, 0, sizeof(c)); len = lena+lenb; for(i=0;i<lena;++i) for(j=0;j<lenb;++j){ c[i+j] += a[i]*b[j]; } for(i=0;i<len;++i){ c[i+1] += c[i]/10; c[i] %= 10; } len++; while(len>0 && !c[len-1]) len--; } int main(){ //freopen("in.txt", "r", stdin); while(cin>>s1>>s2){ lena = strlen(s1); lenb = strlen(s2); for(i=lena-1;i>=0;--i) a[lena-1-i] = s1[i] - '0'; for(i=lenb-1;i>=0;--i) b[lenb-1-i] = s2[i] - '0'; multi(); if(len==0) printf("0"); else for(i=len-1;i>=0;i--) cout<<c[i]; printf("\n"); } //fclose(stdin); return 0; }
相关文章推荐
- Problem 1046 Tempter of the Bone, from http://acm.fzu.edu.cn/problem.php?pid=1046
- Problem 1057 ab from http://acm.fzu.edu.cn/problem.php?pid=1057
- Problem 1478 环形整数串 from http://acm.fzu.edu.cn/problem.php?pid=1478
- Problem 1582 众数问题 from http://acm.fzu.edu.cn/problem.php?pid=1582
- Problem 1410 变位词 from http://acm.fzu.edu.cn/problem.php?pid=1410
- http://acm.fzu.edu.cn/problem.php?pid=2113 数位DP
- Problem 1207 半数集问题 from http://acm.fzu.edu.cn/problem.php?pid=1207
- Problem 1202 信与信封问题 from http://acm.fzu.edu.cn/problem.php?pid=1202
- Problem 1607 Greedy division from http://acm.fzu.edu.cn/problem.php?pid=1607
- fzu 1402 中国剩余定理 http://acm.fzu.edu.cn/problem.php?pid=1402
- http://acm.fzu.edu.cn/problem.php?pid=1564 C(n,k)和素数P的问题
- HDU Today&&http://acm.hdu.edu.cn/showproblem.php?pid=2112
- Beans http://acm.hdu.edu.cn/showproblem.php?pid=2845
- 来个图论,http://acm.hdu.edu.cn/showproblem.php?pid=2112
- hdu 2099 整数的尾数 http://acm.hdu.edu.cn/showproblem.php?pid=2099
- http://acm.hdu.edu.cn/showproblem.php?pid=1020..
- http://acm.hdu.edu.cn/showproblem.php?pid=3584
- http://acm.hdu.edu.cn/showproblem.php?pid=1541 结点更新求最左区间的个数
- http://acm.hdu.edu.cn/showproblem.php?pid=1385
- HDU 1702 队列与栈的简单运用http://acm.hdu.edu.cn/showproblem.php?pid=1702