加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

uva10106(大数)

发布时间:2020-12-14 04:08:31 所属栏目:大数据 来源:网络整理
导读:http://uva.onlinejudge.org/index.php?option=com_onlinejudgeItemid=8page=show_problemproblem=1047 10106 - Product Time limit: 3.000 seconds Product The Problem The problem is to multiply two integers X,Y. ( 0=X,Y10 250 ) The Input The input

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1047

10106 - Product

Time limit: 3.000 seconds

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

12
12
2
222222222222222222222222

Sample Output

144
444444444444444444444444
?题意:就是高精度乘法的计算...
#include<stdio.h>
#include<string.h>
#define maxn 2000
int arr1[maxn],arr2[maxn];
char str1[maxn],str2[maxn];//str1[]输入的第一个数,str2[]输入的第二个数
int result[maxn];//要输出的结果
int main()
{
?memset(str1,sizeof(str1));//清零
?memset(str2,sizeof(str2));//清零
?while(scanf("%s %s",str1,str2)!=EOF)
?{
??memset(result,sizeof(result));
??memset(arr1,sizeof(arr1));
??memset(arr2,sizeof(arr2));
??int k=0,i,j;
??for(i=strlen(str1)-1;i>=0;i--)//arr1[0]保存str1[]个位数......
???arr1[k++]=str1[i]-'0';
??k=0;
??for(i=strlen(str2)-1;i>=0;i--)
???arr2[k++]=str2[i]-'0';//arr2[0]保存str2[]个位数
??for(i=0;i<strlen(str1);i++)
??{
???for(j=0;j<strlen(str2);j++)
????result[i+j]+=arr1[i]*arr2[j];//这个挺好理解的,自己用两个数试试体会下就知道了
??}
??for(i=0;i<maxn;i++)
??{
???if(result[i]>9)//result[i]>9就表示要进位
???{
????result[i+1]+=result[i]/10;
????result[i]%=10;//把进位的保存在后一位
???}
??}
??bool flag=false;
??for(i=maxn;i>=0;i--)
??{
???if(result[i])//只要有一个数字不是0的就可以输出结果这是为了避免输出像000000的这样的数(这样的数直接输出0)
???{
????flag=true;
????break;
???}
??}
??if(flag)
??{
???for(k=i;k>=0;k--)
????printf("%d",result[k]);
??}
??else 
???printf("0");
??printf("n");
??memset(str1,sizeof(str1));
??memset(str2,sizeof(str2));
?}
?return 0;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读