• <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>
            隨筆-65  評論-6  文章-0  trackbacks-0
              1 #include <iostream>
              2 #include <algorithm>
              3 using namespace std;
              4 #define M 8
              5 struct word{
              6     char str[M];
              7     struct word *nextW;
              8 };
              9 struct tree{
             10     bool isOK;
             11     word *head;
             12     struct tree *next[26]; 
             13     tree(){
             14         isOK=false;
             15         head=NULL;
             16         for(int i=0;i<26;i++)
             17             next[i]=NULL;
             18     }
             19 }*root;
             20 char endMark[M]="XXXXXX";
             21 int cmp(char a,char b){
             22     return a<=b;
             23 }
             24 int main(){
             25     freopen("in.txt","r",stdin);
             26     char temp[M],dict[M],sen[105][M];
             27     int w,num=0;
             28     root=new tree;
             29     while (scanf("%s",temp)!=EOF){
             30         if(strcmp(temp,endMark)==0)
             31             break;
             32         bool isP=false;
             33         for(int i=num-1;i>=0;i--){
             34             isP=true;
             35             if(strcmp(sen[i],temp)<0){
             36                 strcpy(sen[i+1],temp);
             37                 num++;
             38                 break;
             39             }
             40             strcpy(sen[i+1],sen[i]);
             41             if(i==0){
             42                 strcpy(sen[0],temp);
             43                 num++;
             44             }
             45         }
             46         if(!isP)
             47             strcpy(sen[num++],temp);
             48     }
             49     w=0;
             50     while (w<num){
             51         strcpy(temp,sen[w++]);
             52         strcpy(dict,temp);
             53         int i,len=strlen(temp);
             54         sort(temp,temp+len,cmp);
             55         tree *cur=root;
             56         for (i=0;i<len;i++){
             57             if(cur->next[temp[i]-'a']==NULL)
             58                 cur->next[temp[i]-'a']=new tree;
             59             cur=cur->next[temp[i]-'a'];
             60         }
             61         cur->isOK=true;
             62         if(cur->head==NULL){
             63             cur->head=new word;
             64             strcpy(cur->head->str,dict);
             65             cur->head->nextW=NULL;
             66         }
             67         else{
             68             word *p=cur->head;
             69             while (p->nextW){
             70                 p=p->nextW;
             71             }
             72             p->nextW=new word;
             73             strcpy(p->nextW->str,dict);
             74             p->nextW->nextW=NULL;
             75         }
             76     }
             77     while (scanf("%s",temp)!=EOF){
             78         if(strcmp(temp,endMark)==0)
             79             break;
             80         int i,len=strlen(temp);
             81         sort(temp,temp+len,cmp);
             82         tree *cur=root;
             83         for(i=0;i<len;i++){
             84             if(cur->next[temp[i]-'a']==NULL)
             85                 break;
             86             cur=cur->next[temp[i]-'a'];
             87         }
             88         if(i<len||!cur->isOK){
             89             puts("NOT A VALID WORD");
             90             puts("******");
             91             continue;
             92         }
             93         word *q=cur->head;
             94         while (q){
             95             printf("%s\n",q->str);
             96             q=q->nextW;
             97         }
             98         puts("******");
             99     }
            100     return 0;
            101 }
            posted on 2012-07-16 09:35 Leo.W 閱讀(375) 評論(0)  編輯 收藏 引用

            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            久久久久亚洲AV无码观看| 久久99精品久久久久久久不卡 | 91久久香蕉国产熟女线看| 婷婷综合久久中文字幕| 久久久久亚洲AV成人网人人软件| 久久久久国色AV免费观看| 无码人妻久久一区二区三区免费| 久久99中文字幕久久| 99久久国产亚洲综合精品| 九九精品99久久久香蕉| 欧美久久一区二区三区| 欧美大香线蕉线伊人久久| 久久综合九色综合欧美就去吻| 亚洲人成伊人成综合网久久久| 国产午夜福利精品久久| 色婷婷综合久久久久中文一区二区| 久久精品国产99久久香蕉| 久久精品蜜芽亚洲国产AV| 18禁黄久久久AAA片| 国产精品女同一区二区久久| 久久精品人人槡人妻人人玩AV| 亚洲另类欧美综合久久图片区| 久久亚洲综合色一区二区三区| 国内精品九九久久精品| 亚洲国产成人久久一区WWW| 999久久久国产精品| 精品久久久久久久| 久久精品毛片免费观看| 亚洲中文字幕无码久久2020 | 久久久久久久综合日本亚洲 | 精品久久久久久久久久中文字幕 | 久久夜色精品国产噜噜麻豆 | 国产精品免费久久久久久久久 | 久久久无码精品亚洲日韩按摩| 亚洲&#228;v永久无码精品天堂久久 | 久久r热这里有精品视频| 久久er99热精品一区二区| 久久精品国产亚洲av高清漫画| 日韩AV无码久久一区二区| 色综合久久久久无码专区| 色偷偷88888欧美精品久久久|