zoukankan      html  css  js  c++  java
  • 高精度乘法

     1 /*
     2     高精度乘法(无负数) 
     3     结构体初始化
     4     定义去除前导0函数
     5     重载赋值符号、乘号
     6     定义字符串输出函数
     7     重载输入输出 
     8 */
     9 #include<bits/stdc++.h>
    10 using namespace std;
    11 const int maxn=10000;
    12 struct bign{
    13     int d[maxn],len;
    14     inline bign() {len=1;memset(d,0,sizeof(d));}
    15     inline void clean() {while(len>1&&!d[len-1]) len--;}
    16     inline bign operator = (const char* num)
    17     {
    18         len=strlen(num);
    19         memset(d,0,sizeof(d));
    20         for(int i=0;i<len;i++) d[i]=num[len-i-1]-48;
    21         return *this;
    22     }
    23     inline bign operator * (const bign &b)
    24     {
    25         bign c;
    26         c.len=len+b.len;
    27         for(int i=0;i<len;i++)
    28         {
    29             int x=0;
    30             for(int j=0;j<b.len;j++)
    31             {
    32                 c.d[i+j]+=x+d[i]*b.d[j];
    33                 x=c.d[i+j]/10;
    34                 c.d[i+j]%=10;
    35             }
    36             c.d[i+b.len]=x;
    37         }
    38         c.clean();
    39         return c;
    40     }
    41     inline string str() const 
    42     {
    43         char s[maxn]={};
    44         for(int i=0;i<len;i++) s[len-i-1]=d[i]+48;
    45         return s;
    46     }
    47 }a,b;
    48 inline istream& operator >> (istream &in,bign &x)
    49 {
    50     char s[maxn]={};
    51     in>>s;
    52     x=s;
    53     return in;
    54 }
    55 inline ostream& operator << (ostream &out,const bign &x)
    56 {
    57     out<<x.str();
    58     return out;
    59 }
    60 int main()
    61 {
    62     cin>>a>>b;
    63     cout<<a*b;
    64     return 0;
    65 } 
  • 相关阅读:
    【NOI2015】品酒大会 SAM
    4566: [Haoi2016]找相同字符 SAM
    3709: [PA2014]Bohater 贪心
    1925: [Sdoi2010]地精部落 dp, 抖动子序列
    4205: 卡牌配对 最大流+建图技巧
    留言板
    self-introduction
    最近比赛
    STOI补番队胡策
    BZOJ 3503: [Cqoi2014]和谐矩阵( 高斯消元 )
  • 原文地址:https://www.cnblogs.com/yu-xing/p/10125435.html
Copyright © 2011-2022 走看看