ACM 3117 高精度练习之乘法(基础)
2014-09-05 21:07
399 查看
3117 高精度练习之乘法
14人推荐 收藏 发题解提交代码
报错
题目描述
输入描述
输出描述
样例输入
样例输出
提示
题目描述 Description
给出两个正整数A和B,计算A*B的值。保证A和B的位数不超过500位。
输入描述 Input Description
读入两个用空格隔开的正整数
输出描述 Output Description
输出A*B的值
样例输入 Sample Input
3 12
样例输出 Sample Output
36
数据范围及提示 Data Size & Hint
两个正整数的位数不超过500位#include <iostream> #include <cstring> using namespace std; #define MAX_N 500 char a[MAX_N+1],b[MAX_N+1]; int ta[MAX_N],tb[MAX_N],tc[MAX_N]; int main() { cin>>a>>b; int lena=strlen(a); int lenb=strlen(b); for(int i=lena-1;i>=0;i--) { ta[lena-i-1]=a[i]-'0'; } for(int i=lenb-1;i>=0;i--) { tb[lenb-i-1]=b[i]-'0'; } for(int i=0;i<lenb;i++) { for(int j=0;j<lena;j++) { tc[i+j]+=ta[j]*tb[i]; } } int lenc=lena+lenb; for(int i=0;i<lenc;i++) { tc[i+1]+=tc[i]/10; tc[i]%=10; } int s=lenc-1; while(!tc[s]) s--; for(int i=s;i>=0;i--) cout<<tc[i]; cout<<endl; return 0; }
相关文章推荐
- 【codevs 3117】高精度练习之乘法
- wikioi天梯之3117 高精度练习之乘法
- 3117 高精度练习之乘法
- code[vs] 3117 高精度练习之乘法
- Codevs 3117 高精度练习之乘法
- 【codevs 3115 3116 3117】高精度练习之加/减/乘法
- 3117 高精度练习之乘法
- codevs 3117 高精度练习之乘法
- 3117 高精度练习之乘法
- codevs 3117 高精度练习之乘法
- 高精度-codevs-3117高精度练习之乘法
- 3117 高精度练习之乘法
- 3117 高精度练习之乘法——http://codevs.cn/problem/3117/
- 【CODEVS3117】高精度练习之乘法
- p3117 高精度练习之乘法
- 33. 高精度练习之乘法
- 基础练习 高精度加法
- 基础练习 矩阵乘法
- 【CodeVS 3123】 高精度练习之超大整数乘法
- 算法竞赛入门经典:第五章 基础题目选解 5.6 数组模拟高精度乘法