Product(大数乘法模板)
来源:互联网 发布:知味观点心实体店 编辑:程序博客网 时间:2024/04/28 00:16
K -Product
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %lluDescription
Product
The Problem
The problem is to multiply two integers X, Y. (0<=X,Y<10250)
The Input
The input will consist of a set of pairs of lines. Each line in pair contains one multiplyer.
The Output
For each input pair of lines the output line should consist one integer the product.
Sample Input
12122222222222222222222222222
Sample Output
144444444444444444444444444
#include <iostream>#include <cstring>#include <cstdio>using namespace std;const int N = 500;int main(){ char a[N],b[N]; while(cin>>a>>b) { if(strcmp(a,"0")==0 || strcmp(b,"0")==0) { cout<<"0"<<endl; continue; } int s[N*10]; memset(s,0,sizeof(s)); int aa[N],bb[N]; memset(aa,0,sizeof(aa)); memset(bb,0,sizeof(bb)); int lena=strlen(a); int lenb=strlen(b); int la=1,lb=1; for(int i=lena-1; i>=0; i--) aa[la++]=a[i]-'0'; for(int i=lenb-1; i>=0; i--) bb[lb++]=b[i]-'0'; for(int i=1; i<la; i++) for(int j=1; j<lb; j++) { s[i+j-1]+= aa[i]*bb[j]; } for(int i=1; i<=la+lb; i++) { s[i+1]+=s[i]/10; s[i]=s[i]%10; } int r=1; for(int i=la+lb; i>=1; i--) { if(s[i]!=0) { r=i; break; } } for(int i=r; i>=1; i--) cout<<s[i]; cout<<endl; } return 0;}
0 0
- Product(大数乘法模板)
- Product(大数乘法)
- UVA Product(大数乘法)
- 大数乘法(模板)
- uva 10106 Product(大数乘法)
- UVA 10106 - Product(大数乘法)
- UVA 10106 Product(大数乘法)
- uva 10106 Product(高精度大数乘法)
- 大数乘法 10106 - Product
- UVA - 10106 Product(大数模板)
- uva 10106 - Product 大数乘法
- UVA 10106-Product(大数乘法)
- 大数与小数模板(乘法,加法)
- 大数乘法模板
- 大数乘法模板
- 大数乘法模板
- 大数乘法模板
- 大数乘法模板
- PCI-E及主板接口实物图
- 黑客攻击的一般流程
- visual assist注释
- C++逆向之switch-case
- tcp/ip基础知识
- Product(大数乘法模板)
- C语言之时间函数
- 泡芙小姐面膜 掀起微商品牌时代!品牌招商微信:361412679
- 引用传回左值,左值可赋值,右值不可赋值
- jstl <c:set>标签
- 还是要来吐槽一下
- [hdu3018]Ant Trip欧拉路
- 不用羡慕别人,我们就是传奇!
- UILabel,UITextField和UIButton使用简示