poj2001字典树
2015-08-10 20:07
351 查看
#include <cstdio> #include <cstring> using namespace std; typedef char st[22]; st str[20003]; st s;int p=0; struct tree_node { int count; tree_node *next[26]; }root ,node[20003]; void insert(char *word) { tree_node *location=&root; while (*word) { if (location ->next[*word-'a']==NULL) { node[p].count=0; location->next[*word-'a']=&node[p++]; } location =location->next[*word-'a']; location->count++; word++; } } void search(char *word) { tree_node *location=&root; while (*word&&location) { if (location->count ==1) break; printf("%c",*word); location=location->next[*word-'a']; word++; } printf("%\n"); return; } int main() { int i=0; while (scanf("%s",str[i])!=EOF) { insert(str[i]); i++; } int n=i; for (i=0;i<n;i++) { printf("%s ",str[i]); search(str[i]); } return 0; }
相关文章推荐
- 事件响应的优先级、stopProgapation禁止下层组件响应
- JVM学习笔记(四)------内存调优
- LintCode-Copy Books
- array_splice()函数
- To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
- [转载] 单表60亿记录等大数据场景的MySQL优化和运维之道 | 高可用架构
- Android Drawable、Bitmap、byte[]之间的转换
- I/O多路复用详解(二)
- JVM学习笔记(三)------内存管理和垃圾回收
- HDu 1513 LCS
- LeetCode 21 Merge Two Sorted Lists
- AndroidManifest:VersionCode和VersionName
- nginx 直接在配置文章中设置日志分割
- fuck
- 字符流---IO学习笔记(三)
- 字符流---IO学习笔记(三)
- 我的金工实习心得(二):铸工第一天
- JVM学习笔记(二)------Java代码编译和执行的整个过程
- C语言-Struct
- VS使用Xamarin连接不上Genymotion的Android模拟器的原因