trie树练习 Hat’s Words
来源:互联网 发布:三星电话交换机编程 编辑:程序博客网 时间:2024/06/06 08:33
Hat’s Words
TimeLimit: 2000/1000 MS(Java/Others)Total Submission(s):2174
Problem Description
A hat’s word is a word in the dictionary that is the concatenationof exactly two other words in the dictionary.
You are to find all the hat’s words in a dictionary.
You are to find all the hat’s words in a dictionary.
Input
Standard input consists of a number of lowercase words, one perline, in alphabetical order. There will be no more than 50,000words.
Only one case.
Only one case.
Output
Your output should contain all the hat’s words, one per line, inalphabetical order.
Sample Input
a
ahat
hat
hatword
hziee
word
Sample Output
ahat
hatword
#include<stdio.h>
#include<string.h>
#include<malloc.h>
{
intflag;
struct node*next[26];
};
struct node*root;
chars[50001][21];
inti;
struct node*p;
p=(structnode*)malloc(sizeof(struct node));
p->flag=0;
for(i=0;i<26;i++)
p->next[i]=NULL;
returnp;
inti;
struct node*p;
p=(structnode*)malloc(sizeof(struct node));
p->flag=0;
p=root;
intlen=strlen(s);
for(i=0;i<len;i++)
{
if(p->next[s[i]-'a']==NULL)
{
p->next[s[i]-'a']=chuangjian();
}
p=p->next[s[i]-'a'];
}
p->flag=1;
inti,n;
n=strlen(s);
struct node*p=root;
for(i=0;i<n;i++)
{
if(p->next[s[i]-'a']==NULL)
return0;
elsep=p->next[s[i]-'a'];
}
returnp->flag;
intn,i,k,m,j;
charstr1[21],str2[21];
root =(structnode*)malloc(sizeof(struct node));
k=1;
while(scanf("%s",s[k])!=EOF)
{
insert(s[k]);
k++;
}
for(i=1;i<k;i++)
{
n=strlen(s[i]);
for(j=1;j<n;j++)
{
for(m=0;m<j;m++)//一点点分来测试
str1[m]=s[i][m];
str1[m]='\0';//一定要加上,不然WA
if(search(str1))
{
intp;
for(p=j;p<n;p++)
str2[p-j]=s[i][p];
str2[p-j]='\0';
if(search(str2))
{
printf("%s\n",s[i]);
break;
}
}
}
}
free(root);
return0;
- trie树练习 Hat’s Words
- hdu 1247 Hat’s Words Trie树
- HDU1247-Hat’s Words(trie树)
- HDU1247 Hat’s Words 【trie树】
- HDU -- 1247 Hat’s Words (Trie 树)
- hdu1247 Hat's words trie树
- Hdu 1247 Hat's Words(Trie树)
- HDU1247 Hat's Words(Trie树,map)
- HDU1247 Hat’s Words【Trie】
- Hat's Words hdu1247 trie
- HDU 1247 Hat’s Words && Trie(字典树)
- HDU 1247 Hat’s Words(字典树Trie)
- HDU 1247 Hat's words(字典树Trie)
- HDU ACM 1247-Hat’s Words-字典树(Trie)
- hdu 1247 Hat’s Words(Trie树入门)
- hdu 1247 Hat’s Words Trie树(+测试数据)
- HDU 1247 Hat’s Words(trie树+STL)
- HDU 1247-Hat’s Words(trie树)
- poj 2299 Ultra-QuickSort 归并排…
- poj 1804 (归并排序求逆序数)Bra…
- 今日免费精品文档<应届毕业生求职…
- 简单的二叉树 hdu 3791
- hdu 1874 畅通工程续(最短路径)
- trie树练习 Hat’s Words
- Unity3D和网页数据交互的基本原理
- trie树Message Flood
- 阿里巴巴程序设计大赛结题报告
- 黑马程序员------面向对象(No.6)(接口、多态)
- 堆排序 hdu 2020 绝对值排序
- (拓扑排序 )hdu 2094 产生冠军
- 排序
- 拓扑排序hdu 3342 Legal or Not