Codevs 3117 高精度练习之乘法
来源:互联网 发布:mac上wine终端怎么用 编辑:程序博客网 时间:2024/05/08 05:07
题目描述 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;int multip(int c[],int length1,int d[],int length2,int e[]){int i,j,temp_e = 0 ;for(i=0 ; i<= length1 - 1 ; i++) //先计算然后处理进位{for(j=0,temp_e=i; j<= length2 - 1 ; j++){e[temp_e++] += d[j] * c[i] ;//temp_e临时变量的使用,方便同位置的相加,不需要乘法完之后再加法}}for(i=0 ; i < temp_e - 1 ; i++){if (e[i] >= 10){e[i+1] += e[i] / 10 ;e[i] %= 10 ;}}return temp_e-1 ;}int main(){char a[500],b[500];int c[500],d[500],e[250000];int length1, length2, length3;int i;memset(c,0,sizeof(c));memset(d,0,sizeof(d));memset(e,0,sizeof(e)); cin>>a;cin>>b; length1 = strlen(a);length2 = strlen(b); for (i = 0; i <= length1-1; i++ ) {c[length1 - i - 1] = a[i] - 48; }for (i = 0; i <= length2-1; i++ ) {d[length2 - i - 1] = b[i] - 48;//转换成int型}length3 = multip(c, length1, d, length2, e);for (i = length3; i >= 0; i--) {cout<< e[i];}cout<< endl;return 0; }
0 0
- 高精度-codevs-3117高精度练习之乘法
- Codevs 3117 高精度练习之乘法
- codevs 3117 高精度练习之乘法
- 【codevs 3115 3116 3117】高精度练习之加/减/乘法
- codevs 高精度乘法 3117
- 3117 高精度练习之乘法
- 3117 高精度练习之乘法
- 3117 高精度练习之乘法
- 【CodeVS 3123】 高精度练习之超大整数乘法
- CODEVS 3123 高精度练习之超大整数乘法
- ACM 3117 高精度练习之乘法(基础)
- code[vs] 3117 高精度练习之乘法
- 高精度-codevs-3115高精度练习之减法
- 高精度-codevs-3116高精度练习之加法
- p3117 高精度练习之乘法
- 1532: 高精度练习之乘法
- codevs天梯高精度乘法
- wikioi天梯之3117 高精度练习之乘法
- 白盒测试&&Java中常用类
- leetcode刷题, 总结,记录, 备忘142
- 菜鸟级springmvc+spring+mybatis整合开发用户登录功能(上)
- iOS自动布局框架Masonry
- 设计模式交流会总结
- Codevs 3117 高精度练习之乘法
- hdu 4715 Difference Between Primes
- 常用Keytool 命令
- HDU——1984 Mispelling4
- Big Number(http://acm.hdu.edu.cn/showproblem.php?pid=1018)
- [转载]IntelliJ IDEA 14.x 创建工作空间与多个Java Web项目
- hdu1588(斐波那契,矩阵连乘)
- codeforces 172B B. Pseudorandom Sequence Period(暴力)
- c++ 面试题