【高精度乘法模板】AOJ-406 Multiplication
来源:互联网 发布:英语六级听力软件推荐 编辑:程序博客网 时间:2024/05/22 13:36
Multiplication
Time Limit: 1000 ms Case Time Limit: 1000 ms Memory Limit: 64 MB
Description
To calculate the result of two numbers by multiply them
Input
The input consists of multiple test cases.
each line contains two numbers A and B (A,B >= 0) which both are less than 100 digits
each line contains two numbers A and B (A,B >= 0) which both are less than 100 digits
Output
Each line contains one result
Sample Input
OriginalTransformed100 10
Sample Output
OriginalTransformed1000
————————————————————低落の分割線————————————————————
思路:string是是实现高精度的利器。
代码如下:
/*ID: j.sure.1PROG:LANG: C++*//****************************************/#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>#include <cmath>#include <stack>#include <queue>#include <vector>#include <map>#include <string>#include <climits>#include <iostream>#define LL long longusing namespace std;const int INF = 0x3f3f3f3f;/****************************************/char A[105], B[105];string str[105];void Add(string &s1, string s2) {int i, j, sum = 0;//if(s1.length() < s2.length()) swap(s1, s2);for(i = s1.length()-1, j = s2.length()-1; i >= 0; i--, j--) { sum += s1[i] - '0'; if(j >= 0) sum += s2[j] - '0'; s1[i] = sum % 10 + '0'; sum /= 10; }if(sum) s1 = '1' + s1;}int main(){#ifdef J_Sure//freopen("000.in", "r", stdin);//freopen(".out", "w", stdout);#endifwhile(~scanf("%s%s", A, B)) {int len_A = strlen(A), len_B = strlen(B);int add, left;for(int i = len_B-1, k = 0; i >= 0, k < len_B; i--, k++) {int _b = B[i] - '0';str[i] = "";add = 0; left = 0;for(int kk = 0; kk < k; kk++)str[i] += '0';for(int j = len_A-1; j >= 0; j--) {int _a = A[j] - '0';int _c = _a * _b + add;add = _c / 10; left = _c % 10;str[i] += left + '0';}if(add)str[i] += add + '0';reverse(str[i].begin(), str[i].end());}for(int i = 1; i < len_B; i++) {Add(str[0], str[i]);}cout << str[0] << endl;}return 0;}
0 0
- 【高精度乘法模板】AOJ-406 Multiplication
- 高精度乘法模板
- 高精度乘法模板
- 高精度乘法FFT 模板
- 高精度乘法模板
- 高精度乘法模板
- 高精度之乘法模板
- 高精度加减乘法模板
- 高精度模板(乘法)
- 我的高精度乘法模板
- poj 2389 Bull Math 高精度乘法模板
- USTC1046 A * B Problem 高精度乘法模板
- 高精度 大数加法 乘法 除法 幂 模板
- 高精度 大数加法 乘法 除法 幂 模板
- 高精度乘法
- 高精度乘法
- 高精度乘法
- 高精度乘法
- 九度oj题目&吉大考研10年机试题全解
- moncler outlet usa-647
- MyEclipse快捷键大全.
- 酷狗笔试题
- 我的代码头文件
- 【高精度乘法模板】AOJ-406 Multiplication
- swift入门教程系列7-控制流
- 第九周项目三(5)——输出星号图
- Dom介绍
- struts2.xml 中result type属性说明
- Online Judge
- SEO
- lamp http://baike.baidu.com/subview/365086/10014223.htm?fr=aladdin
- 第九周项目五填充三