UVA 10106-product (large number multiplication)

Source: Internet
Author: User

ProductTime limit:MS Memory Limit:0KB 64bit IO Format:%lld & %llu SubmitStatus

Description


Product

The problem

The problem is to multiply, integers X, Y. (0<=x,y<10250)

The Input

The input would 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

Note that when the situation is 0, the situation is ignored at first. Don't forget to output 0 when either one is 0


#include <stdio.h> #include <string.h> #include <stdlib.h>char str1[1010],str2[1010];char a[1010],b    [1010],sum[1010];int Main () {int len1,len2;    int i,j;        while (~SCANF ("%s", str1)) {memset (a,0,sizeof (a));        Memset (b,0,sizeof (b));        memset (sum,0,sizeof (sum));        len1= strlen (STR1);        for (i=len1-1;i>=0;i--) a[len1-i-1]=str1[i]-' 0 ';        scanf ("%s", str2);        Len2=strlen (STR2);        for (i=len2-1;i>=0;i--) b[len2-i-1]=str2[i]-' 0 ';            for (i=0;i<len1;i++) {for (j=0;j<len2;j++) sum[i+j]+=a[i]*b[j];                    for (j=0;j<1010;j++) if (sum[j]>=10) {SUM[J+1]+=SUM[J]/10;                sum[j]%=10;        }} int flag=0; for (i=1010;i>=0;i--) {if (flag| |                Sum[i]) {flag=1;            printf ("%d", sum[i]); }} if(!flag) printf ("0");    printf ("\ n"); } return 0;}


UVA 10106-product (large number multiplication)

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.