POJ2389:Bull Math
来源:互联网 发布:淘宝网客服 编辑:程序博客网 时间:2024/06/06 14:21
Description
Bulls are so much better at math than the cows. They can multiply huge integers together and get perfectly precise answers ... or so they say. Farmer John wonders if their answers are correct. Help him check the bulls' answers. Read in two positive integers (no more than 40 digits each) and compute their product. Output it as a normal number (with no extra leading zeros).
FJ asks that you do this yourself; don't use a special library function for the multiplication.
FJ asks that you do this yourself; don't use a special library function for the multiplication.
Input
* Lines 1..2: Each line contains a single decimal number.
Output
* Line 1: The exact product of the two input lines
Sample Input
111111111111111111111111
Sample Output
12345679011110987654321
//一开始没有考虑边界情况,导致溢出了
大数乘法模板题
#include <stdio.h>#include <string.h>void mult(char a[],char b[],char s[]){ int i,j,k = 0,alen,blen,sum = 0,res[650][650]={0},flag = 0; char result[650]; alen = strlen(a); blen = strlen(b); for(i = 0;i<alen;i++) { for(j = 0;j<blen;j++) res[i][j] = (a[i]-'0')*(b[j]-'0'); } for(i = alen-1;i>=0;i--) { for(j = blen-1;j>=0;j--) { sum = sum+res[i+blen-j-1][j]; } result[k] = sum%10; k++; sum = sum/10; } for(i = blen-2;i>=0;i--) { for(j = 0;j<=i;j++) { sum = sum+res[i-j][j]; } result[k] = sum%10; k++; sum = sum/10; } if(sum) { result[k] = sum; k++; } for(i = 0;i<k;i++) result[i]+='0'; for(i = k-1;i>=0;i--) s[i] = result[k-1-i]; s[k] = '\0'; while(1) { if(strlen(s)!=strlen(a) && s[0] == '0') strcpy(s,s+1); else break; }}int main(){ char c[1000],t[1000],sum[100000]; int m; while(~scanf("%s%s",c,t)) { mult(c,t,sum); printf("%s\n",sum); } return 0;}
- POJ2389:Bull Math
- POJ2389 Bull Math
- [高精度] Poj2389 Bull Math
- POJ2389 Bull Math【大数】
- poj2389 Bull Math
- poj2389——Bull Math
- poj2389 Bull Math(大数java)
- 【POJ2389】Bull Math(大数乘法)
- POJ2389《Bull Math》方法:高精度 模拟
- poj2389 Bull Math (高精度之A*B)
- Bull Math
- poj 2389 Bull Math
- Bull Math
- POJ 2389 Bull Math
- Bull Math(P2389)
- POJ 2389 Bull Math
- NOJ [1126] Bull Math
- Bull Math(高精度)
- mina的HTTP性能测试
- 浮点精度转换
- 半边数据结构的相关网站
- 32位和64位的JVM 我该选择哪个呢?
- 用户权限管理
- POJ2389:Bull Math
- 事件循环与线程 一
- 无法识别的属性“targetFramework”
- 探讨Linux kernel中对序列号超前的ACK包的处理
- HttpClient入门
- 关于视频编码有刀切感觉画面的原因
- Android中后台定时任务实现,即时数据同步问题思考
- 类的编程题---还没用到构造函数----自定义日期类
- Listview异步加载图片之优化篇