zoukankan      html  css  js  c++  java
  • 3117 高精度练习之乘法

    3117 高精度练习之乘法

     

    时间限制: 1 s
    空间限制: 128000 KB
    题目等级 : 黄金 Gold
     
     
     
    题目描述 Description

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

    输入描述 Input Description

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

    输出描述 Output Description

    输出A*B的值

    样例输入 Sample Input

    3 12

    样例输出 Sample Output

    36

    数据范围及提示 Data Size & Hint

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

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<string>
     4 #include<cstring>
     5 
     6 using namespace std;
     7 const int N=1001;
     8 
     9 char aa[N];
    10 char bb[N];
    11 int a[N];
    12 int b[N];
    13 int c[N];
    14 
    15 int main()
    16 {
    17     scanf("%s%s",aa,bb);
    18     int la=strlen(aa);
    19     int lb=strlen(bb);
    20     for(int i=0;i<la;i++)
    21        a[i+1]=aa[la-i-1]-'0';
    22     for(int i=0;i<lb;i++)
    23        b[i+1]=bb[lb-i-1]-'0';
    24     
    25     for(int i=1;i<=la;i++)
    26     {
    27         int x=0;
    28         for(int j=1;j<=lb;j++)
    29           {
    30               c[i+j-1]+=a[i]*b[j]+x;
    31               x=c[i+j-1]/10;
    32               c[i+j-1]%=10;
    33           }   
    34         c[i+lb]=x;  
    35     }
    36     int j=lb+la;
    37     while(!c[j]&&j>1) j--;
    38     for(int i=j;i>=1;i--)
    39        cout<<c[i];
    40 }
  • 相关阅读:
    select入门学习
    tomcat入门及相关学习
    Tomcat&Servlet
    CPU排行榜
    CPU后字母代表的含义
    刷 BIOS
    Java的三个体系
    XML入门及案例
    BootStrap笔记
    第三节 DOM及案例 表格全选、表单验证
  • 原文地址:https://www.cnblogs.com/lyqlyq/p/6596923.html
Copyright © 2011-2022 走看看