POJ2503 - Babelfish - 字典树
2014-08-03 16:06
423 查看
#include<stdio.h> #include<string.h> struct tree { int count; tree *next[30]; char c[20]; tree() { count=0; for(int i=0;i<26;i++) { next[i]=NULL; } } }*root; void build(char *ch,char *word) { tree *item=root; for(int i=0;word[i]!=NULL;i++) { int j=word[i]-'a'; if(item->next[j]==NULL) { item->next[j]=new tree; } item=item->next[j]; } item->count=1; strcpy(item->c,ch); } void find(char *word) { tree *item=root; for(int i=0;word[i]!=NULL;i++) { int j=word[i]-'a'; if(item->next[j]==NULL) { puts("eh"); return ; } item=item->next[j]; } if(item->count==1) { printf("%s\n",item->c); return ; } else { puts("eh"); return ; } } int main() { root=new tree; char word[30]; char ch[20]; int i; while(1) { gets(word); if(strlen(word)==0) { break; } for(i=0;word[i]!=' ';i++) { ch[i]=word[i]; } ch[i]=NULL; int t=i; for(i=0;word[t+i];i++) { word[i]=word[i+t+1]; } word[i]=NULL; build(ch,word); } while(gets(word)!=NULL) { find(word); } }
相关文章推荐
- poj 2503 Babelfish(字典树或STL水题) 解题报告(百炼2804)
- POJ 2503 Babelfish 字典树
- poj-2503-Babelfish-字典树
- POJ 2503-Babelfish【字典树】
- poj 2503 Babelfish(字典树)
- POJ_2503_Babelfish【字典树】
- poj 2503:Babelfish(字典树,经典题,字典翻译)
- poj 2503 Babelfish(字典树)
- poj 2503 Babelfish(字典树哈希)
- POJ 2503 Babelfish 字典树应用
- POJ 2503 Babelfish(map,字典树,快排+二分,hash)
- POJ 2503 - Babelfish(字典树)
- poj 2503 Babelfish(字典树或map或哈希或排序二分)
- POJ 2503 Babelfish(map,字典树,快排+二分,hash)
- POJ 2503:Babelfish(字典树入门)
- POJ 2503 Babelfish(字典树)
- POJ 2503 Babelfish(字典树水题)
- POJ 2503 Babelfish map水过,字典树????
- POJ 2503 Babelfish[字典树]
- 文章标题 POJ 2503 : Babelfish(字典树)