• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            我希望你是我獨(dú)家記憶

            一段永遠(yuǎn)封存的記憶,隨風(fēng)而去
            posts - 263, comments - 31, trackbacks - 0, articles - 3
               :: 首頁 :: 新隨筆 ::  :: 聚合  :: 管理

            P2389——高精度乘法

            Posted on 2008-09-03 19:14 Hero 閱讀(174) 評論(0)  編輯 收藏 引用 所屬分類: 代碼如詩--ACM
              1 //2389 Accepted 452K 0MS G++ 2363B PKU
              2 
              3 //高精度乘法
              4 #include <iostream>
              5 using namespace std;
              6 
              7 const int Base=1000000000;
              8 const int Dlen=300;
              9 typedef long long llong;
             10 struct BigInt{
             11     int Len;
             12     int Data[Dlen];
             13     BigInt():Len(0){}
             14     BigInt(const BigInt &num):Len(num.Len){memcpy(Data,num.Data,Len*sizeof*Data);}
             15     BigInt(int num):Len(0){for(;num>0;num/=Base) Data[Len++]=num%Base;}
             16     BigInt &operator=(const BigInt &num){Len=num.Len;memcpy(Data,num.Data,Len*sizeof*Data);return *this;}
             17     int &operator[](int Index){return Data[Index];}
             18     int operator[](int Index)const{return Data[Index];}
             19 };
             20 int compare(const BigInt &A,const BigInt &B){
             21     if(A.Len!=B.Len) return A.Len>B.Len ? 1:-1;
             22     int i;
             23     for(i=A.Len-1;i>=0 && A[i]==B[i];i--);
             24     if(i<0)return 0;
             25     return A[i]>B[i] ? 1:-1;
             26 }
             27 BigInt operator+(const BigInt &A,const BigInt &B){
             28     int i,Carry(0);
             29     BigInt R;
             30     for(i=0;i<A.Len||i<B.Len||Carry>0;i++){
             31         if(i<A.Len) Carry+=A[i];
             32         if(i<B.Len) Carry+=B[i];;
             33         R[i]=Carry%Base;
             34         Carry/=Base;
             35     }
             36     R.Len=i;
             37     return R;
             38 }
             39 BigInt operator-(const BigInt &A,const BigInt &B){
             40     int i,Carry(0);
             41     BigInt R;
             42     R.Len=A.Len;
             43     for(i=0;i<R.Len;i++){
             44         R[i]=A[i]-Carry;
             45         if(i<B.Len) R[i]-=B[i];
             46         if(R[i]<0) Carry=1,R[i]+=Base;
             47         else Carry=0;
             48     }
             49     while(R.Len>0&&R[R.Len-1]==0) R.Len--;
             50     return R;
             51 }
             52 BigInt operator*(const BigInt &A,const int &B){
             53     int i;
             54     llong Carry(0);
             55     BigInt R;
             56     for(i=0;i<A.Len||Carry>0;i++){
             57         if(i<A.Len) Carry+=llong(A[i])*B;
             58         R[i]=Carry%Base;
             59         Carry/=Base;
             60     }
             61     R.Len=i;
             62     return R;
             63 }
             64 istream &operator>>(istream &In,BigInt &num){
             65     char Ch;
             66     for(num=0;In>>Ch;){
             67         num=num*10+(Ch-'0');
             68         if(In.peek()<=' 'break;
             69     }
             70     return In;
             71 }
             72 ostream &operator<<(ostream &Out,const BigInt &num){
             73     int i;
             74     Out<<(num.Len==0 ? 0:num[num.Len-1]);
             75     for(i=num.Len-2;i>=0;i--for(int j=Base/10;j>0;j/=10) Out<<num[i]/j%10;
             76     return Out;
             77 }
             78 
             79 BigInt Bint0(0) ;
             80 BigInt Bint1(1) ;
             81 
             82 BigInt ina, inb, inc ;
             83 BigInt out ;
             84 
             85 int main()
             86 {
             87     while( cin >> ina >> inb )
             88     {
             89         inc = Bint1 ; out = Bint0 ;
             90         forint i=0; i<inb.Len; i++ )
             91         {
             92             inc = ina * inb.Data[i] ;
             93             forint j=0; j<i; j++ ) inc = inc * Base ;
             94             out = out + inc ;
             95         }
             96         
             97 
             98         cout << out << endl ;
             99     }
            100 
            101     return 0 ;
            102 }
            精品国产乱码久久久久软件| 久久99热精品| 2020国产成人久久精品| 亚洲精品无码专区久久久| 久久国产精品无码HDAV| 九九久久精品国产| 久久精品国产99久久无毒不卡| 国内精品久久久久久野外| 色诱久久av| 精品999久久久久久中文字幕| 欧美粉嫩小泬久久久久久久| 久久99精品国产麻豆| 亚洲精品无码久久毛片| 久久r热这里有精品视频| 国产精品美女久久福利网站| 精品久久一区二区| 午夜久久久久久禁播电影| 国产免费久久精品99久久| 久久久久AV综合网成人| 欧美亚洲国产精品久久久久| 久久综合综合久久狠狠狠97色88| 亚洲精品乱码久久久久久久久久久久 | 亚洲国产精品久久久天堂| 久久久久久久综合日本亚洲| 97精品伊人久久久大香线蕉| 久久青青草原亚洲av无码| 久久久久久a亚洲欧洲aⅴ| 亚洲精品蜜桃久久久久久| 亚洲精品乱码久久久久久蜜桃| 国产精品免费看久久久香蕉 | 久久久WWW成人免费毛片| 国产精品久久午夜夜伦鲁鲁| 久久婷婷五月综合国产尤物app| 一级做a爰片久久毛片看看| 久久夜色撩人精品国产| 国产精品久久久99| 久久e热在这里只有国产中文精品99| 久久国产精品久久精品国产| 久久精品国产精品亚洲毛片| 久久久久久人妻无码| 99久久久国产精品免费无卡顿|