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;

    }

  • 相关阅读:
    PHP Notice: Undefined index:解决方法
    javascript监听手机返回键
    jquery判断手指滑动方向
    php 5.5使用 array_column的方法
    html5 点击播放video的方法
    mysql并发量过大造成 update语句更新错误
    html5 微信真机调试方法vConsole
    PHP防止客户端多次点击
    jquery设置html5音量的方法
    设计模式六大原则
  • 原文地址:https://www.cnblogs.com/csgc0131123/p/5290462.html
Copyright © 2011-2022 走看看