UVA 10106 Product (大数相乘)
来源:互联网 发布:知乎 盐水去甲醛 编辑:程序博客网 时间:2024/04/29 15:51
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
大数相乘,网上有很多模板,今下午练练手,自己写一遍,刚开始忽略了前置0,导致0*12=00,0*123=000,后来改了输出就ac了。
#include <iostream>#include <cstring>#define maxn 260using namespace std;int main(){ char str1[maxn],str2[maxn]; while(cin>>str1>>str2){int len1,len2;len1=strlen(str1);len2=strlen(str2);int s1[maxn],s2[maxn];memset(s1,0,sizeof(s1));memset(s2,0,sizeof(s2));int i;for(i=0;i<len1;i++)s1[i]=str1[i]-'0';for(i=0;i<len2;i++)s2[i]=str2[i]-'0';int sum[maxn+maxn];memset(sum,0,sizeof(sum));int j,k;for(i=len2-1;i>=0;i--){for(j=len1-1;j>=0;j--){sum[i+j+1]=sum[i+j+1]+s2[i]*s1[j];}}for(k=len1+len2-1;k>=0;k--)if(sum[k]>=10){int temp;temp=sum[k]%10;sum[k-1]=sum[k-1]+sum[k]/10;sum[k]=temp;}//if(sum[0]!=0)//cout<<sum[0];bool flag=0;for(i=0;i<len1+len2-1;i++){if(sum[i]!=0)flag=1;if(flag==1)cout<<sum[i];}cout<<sum[len1+len2-1];cout<<endl;} return 0;}
0 0
- UVA 10106 - Product (大数相乘问题)
- uva - 10106 - Product(大数相乘)
- UVA 10106 Product (大数相乘)
- uva 10106 Product (大数相乘)
- UVA 10106 Product(大数相乘)
- uva 10106 Product 大数相乘
- Product(大数相乘)
- Uva 10106 Product (高精度相乘)
- uva 10106 Product(大数乘法)
- UVA 10106 - Product(大数乘法)
- UVA 10106 Product(大数乘法)
- uva 10106 Product(高精度大数乘法)
- UVA - 10106 Product(大数模板)
- Product //大数相乘
- uva 10106 - Product 大数乘法
- UVA 10106-Product(大数乘法)
- UVA Product(大数乘法)
- UVA 10106 (大数相乘 13.08.02)
- 简单递归—奇特的数字系列
- [转]TokuMX - 拥有一身MongoDB的外表和一颗TokuDB的心
- poj 2259
- ORACLE恢复删除表或表记录
- Samba服务器安装(通过yum来进行安装)
- UVA 10106 Product (大数相乘)
- CII-2.4指针常量和常量指针
- Netty In Action中文版 - 第十章:单元测试代码
- Android 权限及对应函数 intent 的总结
- 菜鸟的安卓实习之路---布局思想
- Qt入门之connect, SIGNAL, SLOT
- HomeBrew安装MongoDB如何启动
- 逗B少年搞程序12 时间都浪费在无知上了
- js 实现皮肤切换