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 260 char str1[MAXN]; char str2[MAXN]; int s1[MAXN]; int s2[MAXN]; int s[MAXN * 2 + 10]; int main() { int i,j,len1,len2; while(gets(str1) && gets(str2)) { memset(s1,0,sizeof(s1)); memset(s2,0,sizeof(s2)); memset(s,0,sizeof(s)); len1 = strlen(str1); len2 = strlen(str2); j = 0; for(i = len1 - 1; i >=0; i--) { s1[j++] = str1[i] - '0'; } j = 0; for(i = len2 - 1; i >= 0; i--) { s2[j++] = str2[i] - '0'; } for(i = 0; i < len2; i++) { for(j = 0; j < len1; j++) { s[i+j] += s2[i] * s1[j]; } } for(i = 0; i < MAXN * 2 +2; i++) { if(s[i] >= 10) { s[i + 1] += s[i]/10; s[i] %= 10; } } int flag = 0; for(i = MAXN * 2 + 5; i >= 0; i--) { if(flag) { printf("%d", s[i]); } else if(s[i]) { printf("%d", s[i]); flag = 1; } } if(!flag) { printf("0"); } printf("\n"); } return 0; }