Problem E: Product

Problem E: Product
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 18 Solved: 14
[Submit][Status][Web Board]
Description
The problem is to multiply two integers X, Y. (0<=X,Y<10250)

Input
The input will consist of a set of pairs of lines. Each line in pair contains one multiplyer.

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
my answer:

#include<iostream>
#include<cstring>
#include<string>
using namespace std;
int main()
{
 
    char a[100];
    char b[100];
    memset(a,'0',sizeof(a));
    memset(b,'0',sizeof(b));
    while(cin>>a>>b)
    {
        int sum[101]={0};
        int t1=strlen(a);
        int q=t1;
        int t2=strlen(b);
        for(int i=t2-1;t2>0,i>=0;i--){
            int p=100;
            for(int j=q-1,p=100+i-t2+1;j>=0;t1--){
                sum[p--]+=((a[j--]-'0')*(b[i]-'0'));
                }
        }
        for(int k=100;k>=0;k--){
            sum[k-1]+=sum[k]/10;
            sum[k]=sum[k]%10;
        }
        int start=0;
        while(!sum[start])
            start++;
        for(int j=start;j<=100;j++)
           cout<<sum[j];
        cout<<endl;
    }
    return 0;
}

 

posted @ 2014-11-25 12:25  NYNU_ACM  阅读(205)  评论(0编辑  收藏  举报