zoukankan      html  css  js  c++  java
  • 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;

    }

  • 相关阅读:
    作业三
    源代码版本管理与项目管理软件的认识与github的注册
    每周更新的学习进度表
    电脑四则运算出题
    软件工程问题
    自我介绍
    2016.2.14-2016.2.21 中大信(北京)工程造价咨询有限公司实习有感
    《软件工程》课程总结
    结对编程项目---四则运算
    作业三:代码规范、代码复审、PSP
  • 原文地址:https://www.cnblogs.com/csgc0131123/p/5290463.html
Copyright © 2011-2022 走看看