zoukankan      html  css  js  c++  java
  • Uva 10106 Product

     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

    12
    12
    2
    222222222222222222222222
    

    Sample Output

    144
    444444444444444444444444


    #include<stdio.h>
    #include<string.h>
    int main()
    {
        int sum[502],  i, j, t, loop, jlen, ilen, temp, e;
        char inter[251], jnter[251];
        memset(sum, 0, sizeof(sum));
        memset(inter, 0, sizeof(inter));
        memset(jnter, 0, sizeof(jnter));
        while(scanf("%s", inter) != EOF)
        {
            getchar();
            scanf("%s", jnter);
            e = 0;
            ilen = strlen(inter);
            jlen = strlen(jnter);
            for(j=jlen-1; j>=0; --j)
            {
                loop = jlen-1-j;
                for(i=ilen-1; i>=0; --i, ++loop)
                {
                    temp = sum[loop];
                    sum[loop] = (e+sum[loop]+(inter[i]-'0')*(jnter[j]-'0'))%10;
                    e = (e+temp+(inter[i]-'0')*(jnter[j]-'0'))/10;
                }
                for(t=loop; t<502 && e; ++t)
                {
                temp = sum[t];
                sum[t] = (e + sum[t])%10;
                e = (e + temp)/10;
                } 
            }
            
            for(i=501, temp = 0; i>=0; --i)
            {
              if(sum[i] != 0)
                {
                temp = 1;
                printf("%d", sum[i]);
                }
              else if(temp == 1)
                {
                printf("%d", sum[i]);
                }
            }
            if(temp == 0)printf("0");
            printf("\n");
               memset(sum, 0, sizeof(sum));
            memset(inter, 0, sizeof(inter));
            memset(jnter, 0, sizeof(jnter));
        }
        return 0;
    }

    解题报告:

    两个大数相乘,无可厚非按照手工计算的方法进行,知道了两个大数相加这题也就容易了。

  • 相关阅读:
    133
    132
    131
    130
    129
    128
    2019.10.16考试解题报告
    2019.10.15考试解题报告
    洛谷 P1352 没有上司的舞会
    2019.10.13考试解题报告
  • 原文地址:https://www.cnblogs.com/liaoguifa/p/2758092.html
Copyright © 2011-2022 走看看