hdu1671Phone List(字典树---判断有无相同的前缀单词)
来源:互联网 发布:片头制作软件 编辑:程序博客网 时间:2024/05/21 10:32
1.题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1671
2.参考代码:
#include <iostream>#include <cstdio>#include <cstring>using namespace std;struct node{int cnt;node* next[10];node(){cnt=0;memset(next,0,sizeof(next));}}; node* root=new node;void build(char* s){node* p=root;int len=strlen(s);for(int i=0;i<len;i++){if(!p->next[s[i]-'0'])p->next[s[i]-'0']=new node;p=p->next[s[i]-'0'];p->cnt++;}}int find(char* s){node* p=root;int len=strlen(s);for(int i=0;i<len;i++)p=p->next[s[i]-'0'];return p->cnt;}void freedom(node* p){for(int i=0;i<10;i++){if(p->next[i])freedom(p->next[i]);}free(p);}int main(){int t,n,i;char str[10001][30];scanf("%d",&t);while(t--){root=new node;scanf("%d",&n);for(i=0;i<n;i++){scanf("%s",str[i]);build(str[i]);}int flag=0;for(i=0;i<n;i++){if(find(str[i])!=1) ///一旦有一个访问超过一次就说明不可能{flag=0;break;}flag=1;}if(flag)printf("YES\n");elseprintf("NO\n");freedom(root);}return 0;}
- hdu1671Phone List(字典树---判断有无相同的前缀单词)
- hdu1671Phone List - 字典树
- hdu1671Phone List-字典树
- hdu1671Phone List(字典树模板)
- 【字典树】HDU1671Phone List(论释放内存的重要性)
- hdu1247Hat’s Words(字典树---判断单词有无组合现象)
- hdu Phone List 字典树的前缀判断
- poj Phone List 3630 (字典树 判断前缀)
- poj--3630--Phone List(字典树+前缀判断)
- hdu1671Phone List(Trie tree)
- 字典树(Trie树、单词查找树、前缀树)
- 字典树练习(一)hihocoder 1014(求相同前缀的数目)
- hdu1671Phone List
- HDU1671Phone List
- 判断俩个整型数组有无相同的数
- POJ 3630 Phone List(字典树,公共前缀问题)
- hdoj Phone List 1671 (字典树记录前缀)
- HDU 1671-Phone List(字典树-前缀匹配)
- struts.xml中package的namespace属性
- hdu 1702
- 今天去车厂开会,重点谈提高用户体验的问题
- 最小生成树--poj1758
- 从HttpServletRequest中获取域名
- hdu1671Phone List(字典树---判断有无相同的前缀单词)
- hdu 4650 Minimum Average Weight Path
- Android系统信息获取 之七:获取IP地址和MAC地址
- ifstream打开含中文路径文件时失败的问题
- 黑马程序员:毕向东java视频之多线程篇
- hdu 4431 Mahjong,uva 11210 chinese Mahjong,麻将,超快的解法。。
- 深入浅出谈CUDA
- 字符串:KMP Eentend-Kmp 自动机 trie图 trie树 后缀树 后缀数组
- 白盒测试的方法