BZOJ 1754: [Usaco2005 qua]Bull Math 高精乘
来源:互联网 发布:java byte 转换base64 编辑:程序博客网 时间:2024/06/06 09:25
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 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
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[N],s2[N];int a[N],b[N],c[N];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;} /*11111111111111111111111112345679011110987654321*/
阅读全文
0 0
- BZOJ 1754: [Usaco2005 qua]Bull Math 高精乘
- bzoj 1754: [Usaco2005 qua]Bull Math
- 1754: [Usaco2005 qua]Bull Math (高精度乘法)
- bzoj1754 [Usaco2005 qua]Bull Math
- bzoj1754: [Usaco2005 qua]Bull Math
- bzoj1754 [Usaco2005 qua]Bull Math
- bzoj 1751 [Usaco2005 qua]Lake Counting
- BZOJ[1750/3384]: [Usaco2005 qua]Apple Catching
- BZOJ 3384: [Usaco2004 Nov]Apple Catching 接苹果/BZOJ 1750: [Usaco2005 qua]Apple Catching dp
- Bull Math
- bzoj1755 [Usaco2005 qua]Bank Interest
- 1755: [Usaco2005 qua]Bank Interest
- bzoj1751 [Usaco2005 qua]Lake Counting
- bzoj1750 [Usaco2005 qua]Apple Catching
- bzoj1755 [Usaco2005 qua]Bank Interest
- bzoj1751 [Usaco2005 qua]Lake Counting
- [bzoj1751][Usaco2005 qua]Lake Counting
- bzoj1755 [Usaco2005 qua]Bank Interest
- 调整数组位次,奇数的在前面,偶数的在后面。
- 洛谷1478陶陶摘苹果升级版
- 访问java的tomcat服务器以中文命名的HTML网页报错404
- 个人理解的promise
- 时间 杂谈~
- BZOJ 1754: [Usaco2005 qua]Bull Math 高精乘
- ListenableFutureTask的异步回调
- golang中实现RSA(PKCS#1)加密解密
- D-CTF Quals 2016
- 在win32 安装matplotlib,numpy遇到的问题及解决
- 版本管理工具——git
- 搭建python+openCV环境
- 三句话总结JAVA泛型通配符(PECS)
- jquery.min.js multiple markers at this line