• <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>
            我叫張小黑
            張小黑的掙扎生活
            posts - 66,  comments - 109,  trackbacks - 0
            本來都打定主意叫它幾十次,這道題考慮了很多細節,想了很多邊界條件,一次交過了還是沒想到的
            我也不知道這道題到底要不要考慮那些邊界條件,不過看交過的比例,要注意的肯定很多,也許還有應該要想到的
            這是第一次作實數的高精度,寫的很亂,很多都是發現問題后不上去的
              1#include<iostream>
              2using namespace std;
              3#define Max 200
              4#define Max_b 7
              5typedef struct bigint{
              6    int data[Max];//從0開始存儲
              7    int len;
              8    int i;//表示小數位
              9    bigint()
             10    {
             11        memset(data,0,sizeof(data));
             12        len=1;
             13        i=0;
             14    }
             15    friend bigint operator+(bigint,bigint);
             16    friend bigint operator*(bigint,bigint);
             17    void print();//小數點在第i位上,后面有i個小數位
             18    void operator=(const bigint&y){
             19        len=y.len;
             20        for(int j=0;j<y.len;j++)
             21            data[j]=y.data[j];
             22        i=y.i;
             23    }
             24}BIGINT;
             25BIGINT operator+(BIGINT x,BIGINT y)
             26{
             27    BIGINT r;
             28    int rlen=x.len>y.len?x.len:y.len;
             29    int tmp,i,jinwei=0;
             30    for(i=0;i<rlen;i++){
             31        tmp=x.data[i]+y.data[i]+jinwei;
             32        r.data[i]=tmp%10;
             33        jinwei=tmp/10;}
             34    if(jinwei)r.data[rlen++]=jinwei;
             35    r.len=rlen;
             36    return r;
             37}
             38BIGINT operator*(BIGINT x,BIGINT y)
             39{
             40   BIGINT  r;
             41   int i,j;
             42   memset(r.data,0,sizeof(r.data));
             43   r.len=x.len+y.len;
             44   for(i=0;i<x.len;i++)
             45       for(j=0;j<y.len;j++)
             46           r.data[i+j]+=x.data[i]*y.data[j];
             47   for(i=0;i<r.len;i++){
             48       r.data[i+1]+=r.data[i]/10;
             49       r.data[i]%=10;}
             50   while(r.data[i]){
             51       r.data[i+1]+=r.data[i];
             52       r.data[i]%=10;
             53       i++;}
             54   while(i>=0&&!r.data[i])i--;//這個已經消除了開頭的零
             55   //末尾不存在零,不用考慮
             56   if(i!=-1)r.len=i+1;
             57   else r.len=1;//r為0的情況
             58   r.i=x.i+y.i;
             59   return r;
             60}
             61void BIGINT::print()
             62{
             63    int j,k;
             64    for(j=this->len-1;j>=this->i;j--)//輸出了len-i個或是一個也還沒輸出
             65        printf("%d",this->data[j]);
             66    if(j==-1){
             67        putchar('\n');
             68        return;}
             69    putchar('.');
             70    if(j<this->i)//小數點后要補零
             71        for(k=this->i-1;k>j;k--)
             72            putchar('0');
             73    for(;j>=0;j--)
             74        printf("%d",this->data[j]);
             75    putchar('\n');
             76}
             77BIGINT cToBigint(char c[])
             78{
             79    int clen=(int)strlen(c),i=0,j=clen-1,k;
             80    BIGINT result;
             81    memset(result.data,0,sizeof(result.data));
             82    while(c[i]=='0'&&i<clen-1)i++;
             83    while(c[j]=='0'&&j>=0)j--;
             84    if(j>i){
             85        result.len=j-i;
             86        for(j=result.len-1;c[i]!='.';j--,i++)
             87            result.data[j]=c[i]-'0';
             88        result.i=j+1;
             89        for(i++;j>=0;j--,i++)
             90            result.data[j]=c[i]-'0';}
             91    else if(j<i){//
             92        result.len=1;
             93        result.i=0;}
             94    else if(i==j&&c[i]!='.'){//完全就是整數,沒有小數點
             95        for(j=clen-1,k=0;j>=i;j--,k++)
             96            result.data[k]=c[j]-'0';
             97        result.len=k;
             98        result.i=0;
             99    }
            100    return result;
            101}
            102int main()
            103{
            104    BIGINT R,result;
            105    int n,i;
            106    char c[Max_b];
            107    while(scanf("%s %d",c,&n)!=EOF){
            108        memset(result.data,0,sizeof(result.data));
            109        result.i=0;
            110        result.len=1;
            111        R=cToBigint(c);
            112        result.data[0]=1;
            113        for(i=1;i<=n;i++)
            114            result=result*R;
            115        result.print();
            116    }
            117    return 0;
            118}

            posted on 2008-03-09 14:00 zoyi 閱讀(555) 評論(0)  編輯 收藏 引用 所屬分類: acm
            歡迎光臨 我的白菜菜園

            <2008年4月>
            303112345
            6789101112
            13141516171819
            20212223242526
            27282930123
            45678910

            常用鏈接

            留言簿(8)

            隨筆分類

            隨筆檔案

            文章檔案

            相冊

            acmer

            online judge

            隊友

            技術

            朋友

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            99久久er这里只有精品18| 久久婷婷五月综合色奶水99啪| 777午夜精品久久av蜜臀| 国产呻吟久久久久久久92| 久久国产亚洲精品麻豆| 久久亚洲AV成人出白浆无码国产| 婷婷久久五月天| 大香伊人久久精品一区二区 | 波多野结衣久久精品| 日韩中文久久| 四虎国产精品成人免费久久| 狠狠色丁香婷婷久久综合 | 伊人精品久久久久7777| 亚洲国产成人久久综合一区77| 久久中文字幕视频、最近更新| 亚洲国产精品狼友中文久久久| 久久久久亚洲爆乳少妇无| 亚洲人成网站999久久久综合| 青青草原综合久久大伊人| 精品国产乱码久久久久久呢| 无码超乳爆乳中文字幕久久| 久久久无码人妻精品无码| 久久本道伊人久久| 久久精品无码av| 影音先锋女人AV鲁色资源网久久| 无码国内精品久久人妻蜜桃 | 久久久WWW成人免费精品| 四虎国产精品成人免费久久| 精品一二三区久久aaa片| 久久国产高潮流白浆免费观看| 久久久久久久综合日本亚洲| 久久久久久亚洲精品无码| 99久久国产精品免费一区二区| 成人国内精品久久久久影院| a级毛片无码兔费真人久久| 亚洲人AV永久一区二区三区久久| 少妇精品久久久一区二区三区| 欧美久久精品一级c片片| 青青草原综合久久大伊人| 国产成人久久激情91| 伊人久久大香线蕉综合网站|