UVa - 10106 - Product

来源:互联网 发布:包月网络电话卡 编辑:程序博客网 时间:2024/05/17 18:14

题目大意:

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

#include<iostream>#include<stdio.h>#include<string.h>#include<algorithm>#define N 1010using namespace std;char str1[N], str2[N];int ans[N];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

12122222222222222222222222222

Sample Output

144444444444444444444444444

原创粉丝点击