poj2001 http://poj.org/problem?id=2001 简单的字典树题目
2012-10-26 19:25
465 查看
暑假集训的时候 做了10道字典树的题目 今天发现遗忘的狠厉害啊 所以 做了道简单的找感觉。
#include<stdio.h> #include<string.h> struct node { int count; node *next[26]; } root,Root[26000]; int big=0; char work[1010][21]; void buildTree(char *root1) { node *start=&root; while(*root1) { if(start->next[*root1-'a']==NULL) { Root[big].count=0; start->next[*root1-'a']=&Root[big++]; } start=start->next[*root1-'a']; start->count++; root1++; } return ; } void search(char *root1) { node *start=&root; while(*root1) { if(start->count==1) break; printf("%c",*root1); start=start->next[*root1-'a']; if(start==NULL) break; root1++; } } int main() { int k=0; while(scanf("%s",work[k])!=EOF) { buildTree(work[k]); k++; } for(int i=0; i<k; i++) { printf("%s ",work[i]); search(work[i]); printf("\n"); } return 0; }
相关文章推荐
- poj2407简单题目 http://poj.org/problem?id=2407
- 这个题目也是经典的BFS算法,题目的链接如下: http://poj.org/problem?id=1915
- http://poj.org/problem?id=2728&&最优比例生成树
- pku1882 Stamps(http://poj.org/problem?id=1882)(博客搬迁)
- http://poj.org/problem?id=2828
- 独立树Graph Coloring&&http://poj.org/problem?id=1419最大团问题
- poj3295 http://poj.org/problem?id=3295
- Prime Cuts http://poj.org/problem?id=1595
- http://poj.org/problem?id=1456&&并查集
- poj 1915 http://poj.org/problem?id=1915
- http://poj.org/problem?id=1486
- (博客搬迁)pku2231 Moo Volume(数学题http://poj.org/problem?id=2231)
- http://poj.org/problem?id=2983
- http://poj.org/problem?id=3159
- http://poj.org/problem?id=3370
- http://poj.org/problem?id=1598
- Sumdiv&&http://poj.org/problem?id=1845&&约数和问题
- http://poj.org/problem?id=3356&&dp
- http://poj.org/problem?id=2607&&最短路
- http://poj.org/problem?id=1287&&prim