HDU1247 字典树
来源:互联网 发布:安信车辆软件 编辑:程序博客网 时间:2024/05/29 23:45
题意:给出单词字典,问有哪些单词由其他的单词组成,,,,
#include<cstdio>#include<stdlib.h>#include<string.h>#include<string>#include<map>#include<cmath>#include<iostream>#include <queue>#include <stack>#include<algorithm>#include<set>using namespace std;#define INF 1e8#define eps 1e-8#define LL long long#define maxn 26#define mol 1000000007char s[50000][110];struct Trie{ Trie *next[maxn]; int v;}root;void creatTrie(char *str){ int len = strlen(str); Trie *p = &root,*q; for(int i=0;i<len ;i++) { int id =str[i]-'a'; if (p->next[id]==NULL) { q=(Trie *)malloc(sizeof(Trie));q->v=-1;for(int j=0;j<maxn;j++) q->next [j]=NULL;p->next [id]=q;p=p->next [id]; } else { p=p->next[id]; } } p->v=1;}int find (char *str){ int len = strlen(str);Trie *p=&root;for(int i=0;i<len;i++){ int id = str[i]-'a';p = p->next[id];if(p==NULL) return -1;}return p->v ;}int deal(Trie *T){ int i;if(T==NULL) return 0;for(i=0;i<maxn;i++)if(T->next [i]!=NULL)deal(T->next[i]);free(T);return 0;}int main(){int i,n=0;for(i=0;i<maxn;i++)root.next [i]=NULL;while(~scanf("%s",s[n])) creatTrie(s[n++]);char c1[110]={'\0'},c2[110]={'\0'};for(i=0;i<n;i++){ int len=strlen(s[i]); for(int j=0;j<len;j++) { strcpy(c1,s[i]);c1[j]='\0';strcpy(c2,s[i]+j);if (find(c1)==1&&find(c2)==1){ printf("%s\n",s[i]); break;} }} return 0;}
0 0
- HDU1247字典树
- hdu1247 字典树模板
- HDU1247(字典树)
- HDU1247 字典树
- hdu1247字典树
- hdu1247字典树
- 字典树hdu1247
- hdu1247字典树
- hdu1247(字典树/map)
- HDU1247(字典树应用)
- hdu1247 简单的字典树
- hdu1247(字典树+枚举)
- hdu1247 字典树或者hash
- hdu1247-字典树,单词拆分
- hdu1247+hdu1075 字典树基础
- hdu1247(字典树模板)
- 【字典树】 hdu1247 Hat’s Words
- Hat’s Words hdu1247 字典树+搜索
- LeetCode OJ:Populating Next Right Pointers in Each Node II
- 题目1104:整除问题
- TreeMap
- WCF ServiceHost的实例方式及ServiceHost实例的并发方式
- LeetCode OJ:Distinct Subsequences
- HDU1247 字典树
- pku1013
- Live Streaming
- c++学籍管理系统
- LeetCode OJ:Flatten Binary Tree to Linked List
- 浅谈android的跑马灯效果(文字滚动)
- 大学三年积累的教学资源分享和推荐!
- VS2010中仅一次配置opencv的方法
- 机器学习的最佳入门学习资源