【bzoj1754/Usaco2005 qua】Bull Math——高精度乘法
2017-10-13 20:56
211 查看
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. 输入两个数,输出其乘积Input
* Lines 1..2: Each line contains a single decimal number.Output
* Line 1: The exact product of the two input linesSample Input
111111111111111111111111
Sample Output
12345679011110987654321 高精乘高精模版...... 代码:#include<cstdio> #include<cstring> #include<cmath> char b1[45],a1[45]; int a[45],b[45],ans[100]; int main(){ scanf("%s %s",a1+1,b1+1); a[0]=strlen(a1+1);b[0]=strlen(b1+1); for(int i=1;i<=a[0];i++)a[i]=a1[a[0]-i+1]-48; for(int j=1;j<=b[0];j++)b[j]=b1[b[0]-j+1]-48; for(int i=1;i<=a[0];i++){ for(int j=1;j<=b[0];j++){ ans[i+j-1]+=a[i]*b[j]; ans[i+j]+=ans[i+j-1]/10; ans[i+j-1]%=10; } } ans[0]=a[0]+b[0]; while(!ans[ans[0]]&&ans[0]>1)ans[0]--; for(int i=ans[0];i>=1;i--)printf("%d",ans[i]); return 0; }bzoj1754
相关文章推荐
- bzoj 1754: [Usaco2005 qua]Bull Math【高精乘法】
- BZOJ 1754: [Usaco2005 qua]Bull Math
- BZOJ 1754: [Usaco2005 qua]Bull Math 高精乘
- BZOJ1754: [Usaco2005 qua]Bull Math
- bzoj1754: [Usaco2005 qua]Bull Math
- bzoj1754 [Usaco2005 qua]Bull Math
- bzoj1754 [Usaco2005 qua]Bull Math
- bzoj 1754: [Usaco2005 qua]Bull Math
- bzoj1754 [Usaco2005 qua]Bull Math
- 【BZOJ】1754: [Usaco2005 qua]Bull Math
- POJ 2389 Bull Math 高精度(大数)乘法 模板
- POJ 2389 Bull Math 高精度(大数)乘法 模板
- BZOJ 1263 [SCOI2006]整数划分 - 高精度乘法
- Bull Math(高精度——乘法)
- poj 2389 Bull Math 高精度乘法模板
- 1754: [Usaco2005 qua]Bull Math
- 1754: [Usaco2005 qua]Bull Math (高精度乘法)
- 【CodeVS 3123】高精度练习之超大整数乘法 &【BZOJ 2197】FFT快速傅立叶
- BZOJ 2179 [快速傅里叶变换 高精度乘法]
- 高精度之乘法