Hat’s Words
来源:互联网 发布:淘宝制作主图ps视频 编辑:程序博客网 时间:2024/05/19 02:42
Hat’s Words
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 40 Accepted Submission(s) : 12
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
A hat’s word is a word in the dictionary that is the concatenation of 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 per line, in alphabetical order. There will be no more than 50,000 words.
Only one case.
Only one case.
Output
Your output should contain all the hat’s words, one per line, in alphabetical order.
Sample Input
aahathathatwordhzieeword
Sample Output
ahathatword
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
using namespace std;
char a[50005][100];
typedef struct Node
{
Node *child[26];
bool n;
}*tree;
void Insert (tree root, char *str)
{
int len = strlen (str);
tree ans = root,p;
for (int i =0; i < len; i ++)
{
int t=str[i]-'a';
if(ans->child[t]!=NULL)
{
ans=ans->child[t];
}
else
{
p=(tree)calloc(1,sizeof(Node));
p->n=0;
ans->child[t]=p;
ans=p;
}
}
ans->n=1;
}
bool find (tree root,char *str,int x,int y)
{
tree ans = root;
int i,q;
for (i=x;i<y;i++)
{
q=str[i]-'a';
if(ans->child[q]!=NULL)
ans=ans->child[q];
else
return 0;
}
return ans->n;
}
void releas(tree root)
{
int i;
for(i=0;i<26;i++)
if(root->child[i]!=NULL)
releas(root->child[i]);
free(root);
}
int main()
{ int n=0,i,j;
tree root=(tree)calloc(1,sizeof(Node));
root->n=0;
while(scanf("%s",a[n])!=EOF)
{
Insert(root,a[n++]);
}
for(i=0;i<n;i++)
{
int len=strlen(a[i]);
for(j=1;j<len-1;j++)
{
if(find(root,a[i],0,j)&&find(root,a[i],j,len))
{
printf("%s\n",a[i]);
break;
}
}
}
releas(root);
return 0;
}
- HDOJ Hat’s Words
- Hat’s Words
- Hat’s Words
- Hat’s Words
- hdu1247 Hat’s Words
- Hat’s Words
- Hat’s Words
- HDU1247 Hat’s Words
- Hat's words
- hdu1247 Hat’s Words
- Hat’s Words
- Hat’s Words
- hdu1247 hat's words
- Hat’s Words
- hdu1247 Hat’s Words
- hdu1247 Hat’s Words
- Hat’s Words
- Hat’s Words
- JAVA处理日期时间 相加减大全
- 解析 Java 类和对象的初始化过程
- LINK : fatal error LNK1168: cannot open Debug/ling.exe for writing
- Struts2+Hibernate+Spring项目小结
- 在电脑里安装了两个版本的JDk怎样选择eclipse里的工程编译的JDK,以及eclipse里的项目java代码的依赖
- Hat’s Words
- nyoj 214 单调递增子序列(二)
- HDU 3124 Moonmist(平面最近圆对,二分+扫描线)
- ubuntu11下安装并配置samba
- 花样Android ProgressBar 史上最强大讲解
- jQuery 方法 属性
- 16种oracle查询日期语句
- OpenCV 最小二乘拟合方法求取直线倾角
- 【数据库系列】之存储过程与触发器