• 33. 高精度练习之乘法



    时间限制: 1 s

     空间限制: 128000 KB

     题目等级 : 黄金 Gold

    题解

     查看运行结果

    题目描述 Description

    给出两个正整数AB,计算A*B的值。保证AB的位数不超过500位。

    输入描述 Input Description

    读入两个用空格隔开的正整数

    输出描述 Output Description

    输出A*B的值

    样例输入 Sample Input

    3 12

    样例输出 Sample Output

    36

    数据范围及提示 Data Size & Hint

    两个正整数的位数不超过500

    代码:

    #include

    using namespace std;

    #include

    #include

    int main()

    {

     

           string a,b;

           cin>>a>>b;

           int q[504]={0},w[501]={0},c[1002]={0};

           int lenq=a.length();

           int lenw=b.length();

           for(int i=1;i<=lenq;++i)

           q[i]=a[lenq-i]-48;

           for(int i=1;i<=lenw;++i)

           w[i]=b[lenw-i]-48;

           for(int i=1;i<=lenq;++i)

             {

                 int x=0;

                 for(int j=1;j<=lenw;++j)

                 {

                        c[i+j-1]+=q[i]*w[j]+x;

                        x=c[i+j-1]/10;

                        c[i+j-1]%=10;

                    }

                    c[i+lenw]+=x;

             }

           int lenc=lenq+lenw;

           while(c[lenc]==0&&lenc>1)

           lenc--;

           for(int i=lenc;i>=1;--i)

           printf("%d",c[i]);

           return 0;

    }

  • 相关阅读:
    ASP.NET面试题2
    [转]深入.NET DataTable
    C#操作Excel (转)
    XML操作大全
    j2sdk 好用了
    我对“重构(refector)”的看法
    成功执行
    java属性类(Properties类)
    Sharpdevelop下载
    POJ 1753 Flip Game(翻转棋盘+枚举+dfs)
  • 原文地址:https://www.cnblogs.com/csgc0131123/p/5290463.html
Copyright © 2020-2023  润新知