超大整数乘法模板(高精度乘以低精度)
2012-11-29 18:32
375 查看
#include <cstdio> #include <iostream> #include <string> #include <cmath> using namespace std; #define SIZE #define LENGTH 1000 #define LAST LENGTH-2 char a[LENGTH], result[LENGTH]; //multiplier最大值200,000,000,product的初值为0 char *IntegerMultiplication(char *multiplicand, int multiplier, char *product) { int i, j, first, temp[LENGTH]; memset(temp, 0, sizeof(temp)); //将乘积按位保存在temp中,暂不处理进位 for (i = strlen(multiplicand)-1, j = LAST; i >= 0; i--, j--) { temp[j] = (multiplicand[i]-'0') * multiplier; } //获取乘积的首位位置 first = j - (int)log10(multiplier); //处理进位 for (i = LAST; i >= first; i--) { product[i] = temp[i] % 10 + '0'; temp[i-1] += temp[i] / 10; } //去除前导'0' while (product[first] == '0' && first < LAST) { first++; } //返回乘积首位地址 return &product[first]; } int main(void) { int b; while (cin>>a>>b) { memset(result, 0, sizeof(result)); cout<<IntegerMultiplication(a, b, result)<<endl; } return 0; }
相关文章推荐
- 【CodeVS 3123】 高精度练习之超大整数乘法
- CODEVS 3123 高精度练习之超大整数乘法
- 【CodeVS 3123】 高精度练习之超大整数乘法
- cv3123 高精度练习之超大整数乘法(FFT)
- 【CodeVS 3123】高精度练习之超大整数乘法 &【BZOJ 2197】FFT快速傅立叶
- codevs 3123 高精度练习之超大整数乘法
- wikioi3123 高精度练习之超大整数乘法
- 【快速傅里叶变换】【FFT】【WikiOI】【P3132】【高精度练习之超大整数乘法】
- Code[VS] 3123 高精度练习之超大整数乘法
- 3123 高精度练习之超大整数乘法 - Wikioi
- 大精度整数三种运算(加法,减法,乘法)
- 高精度乘法模板
- java中不用BigInteger实现超大整数的乘法操作
- 高精度乘以单精度 hdu1042 N!
- 高精度乘以单精度 Round and Round We Go poj1047
- 一道面试题(C#实现了超大整数的加减乘法运算)
- JAVA模板 大整数模板 高精度
- 高精度模板(乘法)
- 高精度大整数模板(n!为例)
- 整数乘法优化问题(乘以常数)(转…