您的位置:首页 > 其它

BZOJ 1754: [Usaco2005 qua]Bull Math 高精乘

2017-06-18 16:24 531 查看

1754: [Usaco2005 qua]Bull Math

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 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 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 lines

Sample Input

11111111111111

1111111111

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
*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: