bzoj1754 [Usaco2005 qua]Bull Math
2014-07-12 21:04
393 查看
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
12345679011110987654321bzoj水题二连发……高精乘法随便写就行了
#include<cstdio> char s1[101],s2[101]; int l1,l2,l3; int a[101],b[101],c[101]; int main() { scanf("%s%s",s1,s2); while (s1[l1]>='0'&&s1[l1]<='9')l1++; while (s2[l2]>='0'&&s2[l2]<='9')l2++; for (int i=1;i<=l1;i++) a[l1-i+1]=s1[i-1]-'0'; while (!a[l1])l1--; for (int i=1;i<=l2;i++) b[l2-i+1]=s2[i-1]-'0'; while (!b[l2])l2--; for (int i=1;i<=l1;i++) for (int j=1;j<=l2;j++) c[i+j-1]+=a[i]*b[j]; for (int i=1;i<=l1+l2+2;i++) { while (c[i]>9) { c[i]-=10; c[i+1]++; } } for (l3=l1+l2+3;l3;l3--) if (c[l3]) break; for (int i=l3;i>=1;i--) printf("%d",c[i]); }
相关文章推荐
- BZOJ 1754: [Usaco2005 qua]Bull Math
- 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
- bzoj 1754: [Usaco2005 qua]Bull Math【高精乘法】
- bzoj1754 [Usaco2005 qua]Bull Math
- bzoj1754 [Usaco2005 qua]Bull Math
- 1754: [Usaco2005 qua]Bull Math (高精度乘法)
- 1754: [Usaco2005 qua]Bull Math
- BZOJ 3384: [Usaco2004 Nov]Apple Catching 接苹果/BZOJ 1750: [Usaco2005 qua]Apple Catching dp
- [bzoj1751][Usaco2005 qua]Lake Counting
- bzoj 1753: [Usaco2005 qua]Who's in the Middle【排序】
- 【bzoj1754/Usaco2005 qua】Bull Math——高精度乘法
- BZOJ 1755 [USACO 2005 Qua] Bank Interest 快速幂
- BZOJ[1750/3384]: [Usaco2005 qua]Apple Catching
- bzoj1751 [Usaco2005 qua]Lake Counting
- bzoj1751 [Usaco2005 qua]Lake Counting
- BZOJ1753: [Usaco2005 qua]Who's in the Middle