hdu1247 Hat’s Words
来源:互联网 发布:ie无法加载java插件 编辑:程序博客网 时间:2024/05/21 11:15
http://acm.hdu.edu.cn/showproblem.php?pid=1247
#include<iostream>#include<string>#include<algorithm>using namespace std;struct tire{ bool isword; tire *next[26];};tire *head;string s[50010];bool cmp(string a,string b){ return a.size()<b.size();}void Insert(string s){ int i,j; tire *t=head,*p; for(i=0;i<s.size();i++) { int id=s[i]-'a'; if(t->next[id]==NULL) { p=new tire; for(j=0;j<26;j++) { p->next[j]=NULL; } p->isword=false; t->next[id]=p; } t=t->next[id]; if(t->isword==NULL)t->isword=false; if(i==s.size()-1)t->isword=true; }}bool Find(string s){ tire *T=head,*t; int i,j; for(i=0;i<s.size();i++) { int id=s[i]-'a'; if(T->next[id]==NULL)return false; else { T=T->next[id]; if(T->isword==true) { t=head; for(j=i+1;j<s.size();j++) { id=s[j]-'a'; if(t->next[id]==NULL)break; else { t=t->next[id]; } } if(j>=s.size()) { if(t->isword==true)return true; } } } } return false;}int main(){ int i=0,sum=0,j=0,n; string a; head=new tire; for(j=0;j<26;j++) { head->next[j]=NULL; } head->isword=false; while(cin>>a) { s[i]=a; i++; } n=i; for(i=0;i<n;i++)//先把输入的数据全部储存到字典树 { Insert(s[i]); } for(i=0;i<n;i++) { if(Find(s[i])==true)cout<<s[i]<<endl; } return 0;}
0 0
- hdu1247 Hat’s Words
- HDU1247 Hat’s Words
- hdu1247 Hat’s Words
- hdu1247 hat's words
- hdu1247 Hat’s Words
- hdu1247 Hat’s Words
- hdu1247 Hat’s Words
- hash hdu1247 Hat’s Words
- HDU1247 Hat’s Words【Trie】
- Hat's Words hdu1247 trie
- 【字典树】 hdu1247 Hat’s Words
- Hat’s Words hdu1247 字典树+搜索
- HDU1247-Hat’s Words(字典树)
- Hat’s Words(hdu1247字典树)
- hdu1247 Hat’s Words (字典树)
- hdu1247 Hat’s Words(字典树)
- HDU1247-Hat’s Words(trie树)
- HDU1247 Hat’s Words 【trie树】
- 单向链表的建立,添加与删除
- VC版AddLog
- 友元函数
- Ubuntu中支持yum命令
- linux and Android 重新开始
- hdu1247 Hat’s Words
- 网页访问性能
- 学习 Linux内核的意义及内核 head_list分析
- Saruman's Army 贪心 POJ
- 系统移植_好博客
- android中ViewConfiguration的简单介绍
- Android Studio 简单介绍和使用问题小结
- 浅析PC机串口通讯流控制
- leetcode-Swap Nodes in Pairs