BZOJ 1754: [Usaco2005 qua]Bull Math 高精乘
2017-06-18 16:24
531 查看
1754: [Usaco2005 qua]Bull Math
Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 543 Solved: 343
[Submit][Status][Discuss]
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 himcheck 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<ctime>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<map>
#include<set>
#define Pi acos(-1)
using namespace std;
typedef double db;
inline int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch<='9'&&ch>='0'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
return x*f;
}
const int N=110;
char s1
,s2
;
int a
,b
,c
;
int main()
{
scanf("%s%s",s1,s2);
int lena=strlen(s1),lenb=strlen(s2);
for(int i=0;s1[i];i++)a[lena-i]=s1[i]-'0';
for(int i=0;s2[i];i++)b[lenb-i]=s2[i]-'0';
for(int i=1;i<=lena;i++)
for(int j=1;j<=lenb;j++)
{c[i+j-1]+=a[i]*b[j];}
for(int i=1;i<=lena+lenb+2;i++)
{
if(c[i]>=10)
{
c[i+1]+=c[i]/10;
c[i]%=10;
}
}
int lenc;
for(lenc=lena+lenb+3;lenc>0;lenc--)if(c[lenc])break;
for(int i=lenc;i;i--)printf("%d",c[i]);
puts("");
return 0;
}
/*
11111111111111
1111111111
12345679011110987654321
*/
相关文章推荐
- bzoj1754 [Usaco2005 qua]Bull Math
- BZOJ 1754: [Usaco2005 qua]Bull Math
- 【BZOJ】1754: [Usaco2005 qua]Bull Math
- bzoj1754: [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
- 1754: [Usaco2005 qua]Bull Math (高精度乘法)
- 1754: [Usaco2005 qua]Bull Math
- bzoj1750 [Usaco2005 qua]Apple Catching
- bzoj 1755: [Usaco2005 qua]Bank Interest【模拟】
- bzoj1751 [Usaco2005 qua]Lake Counting
- bzoj1751 [Usaco2005 qua]Lake Counting
- bzoj1751 [Usaco2005 qua]Lake Counting
- bzoj 1751 [Usaco2005 qua]Lake Counting
- BZOJ1753 [Usaco2005 qua]Who's in the Middle
- bzoj1753 [Usaco2005 qua]Who's in the Middle
- BZOJ 3384: [Usaco2004 Nov]Apple Catching 接苹果/BZOJ 1750: [Usaco2005 qua]Apple Catching dp