Bull Math(高精度)
来源:互联网 发布:中国it人才网 编辑:程序博客网 时间:2024/04/30 07:39
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
解题思路:
普通的高精度乘法题。
AC代码:
#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int maxn = 100;int main(){ int num_1[maxn], num_2[maxn], length_1, length_2, result[maxn * 2]; char str_1[maxn], str_2[maxn]; scanf("%s%s", str_1, str_2); memset(num_1, 0, sizeof(num_1)); memset(num_2, 0, sizeof(num_2)); memset(result,0,sizeof(result)); length_1 = strlen(str_1); length_2 = strlen(str_2); for(int i = 0; i < length_1; i++) { num_1[i] = str_1[length_1-i-1] - '0'; } for(int i = 0; i < length_2; i++) { num_2[i] = str_2[length_2-i-1] - '0'; } for(int i = 0; i < length_1; i++) for(int j = 0; j < length_2; j++) { result[i + j] += num_1[i] * num_2[j]; } for(int i = 0; i < maxn * 2; i++) { if(result[i] >= 10) { result[i + 1] += result[i]/10; result[i] %= 10; } } bool isBegin = false; for(int i = maxn * 2 - 1; i >= 0; i--) { if(isBegin) printf("%d",result[i]); else if(result[i]) { printf("%d",result[i]); isBegin = true; } } if(!isBegin) printf("0"); return 0;}
0 0
- Bull Math(高精度)
- Bull Math(高精度)
- poj 2389 Bull Math(高精度加法)
- Bull Math(高精度——乘法)
- [高精度] Poj2389 Bull Math
- POJ 2389 Bull Math 高精度(大数)乘法 模板
- poj2389 Bull Math (高精度之A*B)
- poj 2389 Bull Math 高精度乘法模板
- POJ2389《Bull Math》方法:高精度 模拟
- 1754: [Usaco2005 qua]Bull Math (高精度乘法)
- Bull Math(大数乘法)
- Bull Math
- Bull Math(java大数相乘)
- POJ 2389 Bull Math(FFT)
- POJ 2389 Bull Math (FFT)
- poj2389bull math(高精度)
- poj 2389 Bull Math
- Bull Math
- linux 下 apache2和subverion的通用安装和配置(无权限)
- 获取最新职位通过在线作业分类
- 并查集PID36 / 数石子
- 学习Weblogic和JAVA的一些笔记-Xms Xmx PermSize MaxPermSize的含义
- Tomcat中Connector常用配置
- Bull Math(高精度)
- Linux 下IPV6配置
- 蓝光卷烟回顾为什么是蓝的CIGS热
- ORACLE 更新插入数据
- Java中如何使封装自己的类,建立并使用自己的类库?
- OSI七层模型与TCP/IP五层模型
- 苹果iPhone 3G比。的LG KU990 Viewty产品 - 是的Viewty真的优于iPhone 3G的
- 关于ALT+/快捷键的提示问题
- 回调函数及其在C语言中的使用