Ultraviolet A 10106

Source: Internet
Author: User

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 shoshould consist one integer the product.

Sample Input
12
12
2
222222222222222222222222
Sample Output
144
444444444444444444444444

#include <stdio.h>#include <string.h>#define MAXN 260char 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;}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.