您的位置:首页 > 其它

UVa - 10106 - Product

2013-08-08 14:50 357 查看
题目大意:

求两个数的乘积,用高精度写。但要注意结果为0 的情况!

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define N 1010

using namespace std;

char str1
, str2
;
int ans
;

int main()
{
int i, j;
while (scanf("%s", str1) != EOF)
{
memset(ans, 0, sizeof(ans));
reverse(str1, str1 + strlen(str1));
scanf("%s", str2);
reverse(str2, str2 + strlen(str2));
for (i = 0; i < strlen(str1); i ++)
{
for (j = 0; j < strlen(str2); j ++)
{
ans[i + j] += (str1[i] - '0') * (str2[j] - '0');
if (ans[i + j] > 9)
{
ans[i + j + 1] += ans[i + j] / 10;
ans[i + j] %= 10;
}
}
}
for (j = 1009; j >= 0; j --)
{
if (ans[j] != 0)
{
break;
}
if (j == 0)
{
printf("0");
}
}
for (i = j; i >= 0; i --)
{
printf("%d", ans[i]);
}
printf("\n");
}
return 0;
}


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