• <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>

            pku 1706 References 簡單hash

            題意很簡單,把文章中的引用信息整理到最后并給它們重新編號。。我想不懂為什么我自己寫hash效率那么低。。。還有就是看清題目,空行是僅僅包括空格、TAB、回車的行
              1 # include <stdio.h>
              2 # include <stdlib.h>
              3 # include <string.h>
              4 //char tmp[100];
              5 struct part
              6 {
              7     char tmp[3][100];
              8     int c;
              9     int id;
             10 }refer[40001];
             11 int c=0,hashc=1;
             12 int hash_map[100001][2];
             13 void puthash(int num,int val)
             14 {
             15     int h=num%99997;
             16     while(hash_map[h][0]!=-1&&hash_map[h][0]!=num)
             17          h=(h+1)%100000;
             18     if(hash_map[h][0]==-1)
             19     {
             20         hash_map[h][0]=num;
             21         hash_map[h][1]=val;
             22 
             23     }
             24 }
             25 int gethash(int num)
             26 {
             27     int h=num%99997;
             28     while(hash_map[h][0]!=-1&&hash_map[h][0]!=num)
             29              h=(h+1)%100000;
             30     if(hash_map[h][0]==-1)
             31         return -1;
             32     else
             33         return hash_map[h][1];
             34 }
             35 int cmp(const void *a,const void *b)
             36 {
             37     struct part *aa=(struct part *)a;
             38     struct part *bb=(struct part *)b;
             39     return aa->id-bb->id;
             40 }
             41 int emptyline(char *str)
             42 {
             43     int i;
             44     if(strlen(str)==0return 1;
             45     for(i=0;i<strlen(str);i++)
             46       if(str[i]!=' '&&str[i]!='\t')
             47         return 0;
             48     return 1;   
             49 }
             50 int main()
             51 {
             52 //    freopen("input.txt","r",stdin);
             53 //    freopen("ans.txt","w",stdout);
             54     int i,j;
             55         char str[100];
             56     int jud=0;
             57     memset(hash_map,-1,sizeof(hash_map));
             58     
             59     while(gets(str))
             60     {
             61         //if(!strcmp(str,"---")) break;
             62         if(str[0]=='[')
             63         {
             64             for(i=0;str[i]!=']';i++);
             65             str[i]='\0';
             66             refer[c].id=atoi(str+1);
             67             refer[c].c=0;
             68             strcpy(refer[c].tmp[refer[c].c++],str+i+1);
             69             while(gets(str))
             70             {
             71                 if(emptyline(str)) break;
             72                     
             73                 else
             74                 {
             75                     strcpy(refer[c].tmp[refer[c].c++],str);
             76                 }
             77             }
             78             c++;
             79         }
             80         else if(emptyline(str)) continue;
             81         else
             82         {
             83             if(jud==0)
             84                 jud=1;
             85             else
             86                 printf("\n");
             87             do
             88             {
             89                 if(emptyline(str)) break;
             90 
             91                 for(i=0;i<strlen(str);i++)
             92                 {
             93                     if(str[i]!='[')
             94                         printf("%c",str[i]);
             95                     else
             96                     {
             97                         int num,h;
             98                         for(j=i;str[j]!=']';j++);
             99                         str[j]='\0';
            100                         num=atoi(str+i+1);
            101                         str[j]=']';
            102                         h=gethash(num);
            103                         if(h==-1)
            104                         {
            105                             puthash(num,hashc);
            106                             h=hashc++;
            107                         }
            108                         printf("[%d]",h);
            109                         i=j;
            110                     }
            111                 }
            112                 printf("\n");
            113                 
            114             }while(gets(str));
            115         }
            116     }
            117     for(i=0;i<c;i++)
            118     {
            119         int res=gethash(refer[i].id);
            120         if(res==-1)
            121         {
            122             puthash(refer[i].id,hashc);
            123             res=hashc++;
            124         }
            125         refer[i].id=res;
            126     }
            127     qsort(refer,c,sizeof(struct part),cmp);
            128 
            129     for(i=0;i<c;i++)
            130     {
            131         printf("\n");
            132         printf("[%d]",refer[i].id);
            133         for(j=0;j<refer[i].c;j++)
            134             printf("%s\n",refer[i].tmp[j]);
            135     }
            136 printf("\n");
            137     return 0;
            138 }
            139 



            posted on 2010-11-07 02:54 yzhw 閱讀(249) 評論(0)  編輯 收藏 引用 所屬分類: data structsimple problem~

            <2010年10月>
            262728293012
            3456789
            10111213141516
            17181920212223
            24252627282930
            31123456

            導(dǎo)航

            統(tǒng)計

            公告

            統(tǒng)計系統(tǒng)

            留言簿(1)

            隨筆分類(227)

            文章分類(2)

            OJ

            最新隨筆

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            久久噜噜电影你懂的| 色综合久久综合中文综合网| 亚洲国产精品久久久久婷婷软件| 精品久久综合1区2区3区激情| 精品久久久久久国产免费了| 人妻无码久久精品| 国产综合久久久久| 久久久久久久女国产乱让韩| 久久久91精品国产一区二区三区 | 伊人久久大香线蕉av一区| 久久久91精品国产一区二区三区| 久久99热这里只频精品6| 一级做a爰片久久毛片人呢| 韩国免费A级毛片久久| 久久精品国产色蜜蜜麻豆| 亚洲国产日韩欧美综合久久| 色综合久久最新中文字幕| 精品亚洲综合久久中文字幕| 亚洲第一极品精品无码久久| 2021国产精品久久精品| 亚洲av成人无码久久精品| 人妻少妇久久中文字幕一区二区 | 色狠狠久久综合网| 久久精品综合网| 精品国产乱码久久久久久呢| 日韩乱码人妻无码中文字幕久久| 久久夜色精品国产网站| 99久久免费国产特黄| 日韩美女18网站久久精品| 国产精品成人久久久| 久久久综合九色合综国产| 日产精品久久久久久久| 久久国产精品久久| 99久久99久久精品国产片果冻 | 欧美va久久久噜噜噜久久| 亚洲国产精品人久久| 久久人人妻人人爽人人爽| 国产成人久久精品麻豆一区 | 精品国产乱码久久久久软件| 久久精品国产亚洲网站| 午夜不卡久久精品无码免费|