http://acm.hdu.edu.cn/showproblem.php?pid=1251&&字典树
来源:互联网 发布:商务印书馆 知乎 编辑:程序博客网 时间:2024/06/05 23:43
字典树水题,求公共前缀的个数。。。
#include<iostream>#include<string.h>#include<string>#include<stdlib.h>using namespace std;typedef struct Tire{int count; struct Tire *next[26];}*Node,T;Node a;void init(){a=(Node)malloc(sizeof(T));for(int i=0;i<26;++i)a->next[i]=NULL;}void insert(string s){ Node head=a;int n=s.size();for(int i=0;i<n;++i){int k=(int)(s[i]-97);if(head->next[k]==NULL){head->next[k]=new T;head=head->next[k];head->count=1;for(int i=0;i<26;++i)head->next[i]=NULL;}else { head=head->next[k]; head->count++; }}}int find(string s){int n=s.size();Node head=a;for(int i=0;i<n;++i){int k=(int)(s[i]-97);if(head->next[k]) head=head->next[k];else return 0;}return head->count;}int main(){ char ch[10]; init();while(gets(ch),strcmp(ch,""))insert(ch);while(gets(ch))cout<<find(ch)<<endl;return 0;}
- http://acm.hdu.edu.cn/showproblem.php?pid=1251&&字典树
- http://acm.hdu.edu.cn/showproblem.php?pid=1075&&字典树
- http://acm.hdu.edu.cn/showproblem.php?pid=1005
- http://acm.hdu.edu.cn/showproblem.php?pid=1333
- http://acm.hdu.edu.cn/showproblem.php?pid=2710
- http://acm.hdu.edu.cn/showproblem.php?pid=2866
- http://acm.hdu.edu.cn/showproblem.php?pid=1041
- http://acm.hdu.edu.cn/showproblem.php?pid=1719
- http://acm.hdu.edu.cn/showproblem.php?pid=2136
- http://acm.hdu.edu.cn/showproblem.php?pid=1166
- http://acm.hdu.edu.cn/showproblem.php?pid=3519
- http://acm.hdu.edu.cn/showproblem.php?pid=2446
- http://acm.hdu.edu.cn/showproblem.php?pid=1709
- http://acm.hdu.edu.cn/showproblem.php?pid=1874
- http://acm.hdu.edu.cn/showproblem.php?pid=1863
- http://acm.hdu.edu.cn/showproblem.php?pid=1879
- http://acm.hdu.edu.cn/showproblem.php?pid=1875
- http://acm.hdu.edu.cn/showproblem.php?pid=1102
- 第四周实验报告(四)
- crsctl命令详解
- MySQL 按条件导出某部分数据
- 嵌入式开发资料集锦
- 浏览器关于scrollTop scrollLeft的兼容性
- http://acm.hdu.edu.cn/showproblem.php?pid=1251&&字典树
- HDU 2141 二分
- [debian安装]termial在gnome中无法真透明
- 进程和线程的区别
- MFC对话框美化使其具有xp/win7风格
- MFC创建控件--CButton
- 元年
- POJ-3070 Fibonacci【矩阵二分幂】
- linux2.6.32.2 mini2440平台移植--移植DM9000网卡驱动