[高精度] Poj2389 Bull Math
来源:互联网 发布:java list clear 编辑:程序博客网 时间:2024/05/17 22:42
D - Bull Math
Time Limit:1000MS Memory Limit:65536KB
64bit IO Format:%I64d & %I64u
Status
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.
Input
* Lines 1..2: Each line contains a single decimal number.
Output
* Line 1: The exact product of the two input lines
Sample Input
11111111111111
1111111111
Sample Output
12345679011110987654321
题意很好理解,也可以看样例输入输出就知道了,大数乘法模板题。
具体重点看大数模板的输入,输出以及使用方法。
#include <iostream>#include<cstdio>#include<cstring>using namespace std;struct BigInt{ const static int mod = 10000; const static int DLEN =4; int a[600],len; BigInt(){ memset(a,0,sizeof(a)); len = 1; } BigInt(const char s[]) { memset(a,0,sizeof(a)); int L = strlen(s); len = L/DLEN; if(L%DLEN)len++; int index = 0; for(int i = L-1;i>=0;i-=DLEN) { int t = 0; int k = i-DLEN +1; if(k<0) k=0; for(int j = k;j<=i;j++) t = t*10 + s[j] - '0'; a[index++] = t; } } BigInt operator *(const BigInt &b)const { BigInt res; for(int i = 0;i<len; i++) { int up = 0; for(int j = 0 ; j < b.len;j++) { int temp = a[i] * b.a[j] + res.a[i+j] +up; res.a[i+j] = temp % mod; up = temp / mod; } if (up != 0) res.a[i+b.len] = up; } res.len = len+b.len; while(res.a[res.len - 1] == 0 && res.len >1) res.len--; return res; } void output() { printf("%d",a[len-1]); for(int i = len-2; i>=0;i--) printf("%04d",a[i]); printf("\n"); }};int main(){ char ch1[600]; char ch2[600]; scanf("%s",ch1); scanf("%s",ch2); BigInt A(ch1); BigInt B(ch2); BigInt C = A * B; C.output(); return 0;}
- [高精度] Poj2389 Bull Math
- POJ2389《Bull Math》方法:高精度 模拟
- POJ2389:Bull Math
- POJ2389 Bull Math
- POJ2389 Bull Math【大数】
- poj2389 Bull Math
- poj2389 Bull Math (高精度之A*B)
- poj2389——Bull Math
- poj2389 Bull Math(大数java)
- 【POJ2389】Bull Math(大数乘法)
- Bull Math(高精度)
- Bull Math(高精度)
- poj 2389 Bull Math 高精度乘法模板
- poj 2389 Bull Math(高精度加法)
- 1754: [Usaco2005 qua]Bull Math (高精度乘法)
- Bull Math(高精度——乘法)
- POJ 2389 Bull Math 高精度(大数)乘法 模板
- Bull Math
- jQuery动态添加的元素绑定事件处理函数代码
- win7 64位系统,vs2010下配置OpenGL开发环境
- 几种线程池的使用详解
- assert()函数用法总结
- Web.xml配置详解
- [高精度] Poj2389 Bull Math
- Spring MVC 后台获取前台form参数值(requestparam)
- SAS一般语法
- 中断与中断处理(二)
- 手动脱Mole Box V2.6.5壳实战
- Python 3.4 install lxml
- 六款值得推荐的android(安卓)开源框架简介
- ASP的2种开发模式
- dns服务器