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;
    }

    解题报告:

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

  • 相关阅读:
    canvas直线学习
    移动端页面练习
    IOS 本地推送(UILocalNotification)
    IOS 社交分享
    IOS 通讯录 (访问,添加,修改)
    IOS 蓝牙(GameKit、Core Bluetooth)
    IOS 获取更多的设备信息
    IOS 摇一摇的方法
    IOS Core Motion、UIAccelerometer(加速计使用)
    IOS UIDevice距离传感器(打开 关闭)
  • 原文地址:https://www.cnblogs.com/liaoguifa/p/2758092.html
Copyright © 2011-2022 走看看