hdu 1247 Hat’s Words 字典树
来源:互联网 发布:金手指炒股软件 编辑:程序博客网 时间:2024/05/21 10:48
点击打开链接题目链接
Hat’s Words
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7870 Accepted Submission(s): 2851
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
输出所有的hat‘s words
#include<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>#include<iostream>using namespace std;struct node{ node *next[26]; int end;};node *head;char str[50500][100];void tree_add(char *str){ node *t,*s=head; int i,j; int l=strlen(str); for(i=0;i<l;i++) { int id=str[i]-'a'; if(s->next[id]==NULL) { t=new node; for(j=0;j<26;j++) { t->next[j]=NULL; } t->end=0; s->next[id]=t; } s=s->next[id]; } s->end=1;}int tree_search(char *str){ int l=strlen(str); int i,j,id; node *s=head; for(i=0;i<l;i++) { id=str[i]-'a'; if(s->next[id]==NULL) return 0; s=s->next[id]; } return s->end;}int main(){ int n=0; head=new node; int i,j; char left[100],right[100]; for(i=0;i<26;i++) { head->next[i]=NULL; } head->end=0; while(gets(str[n])!=NULL&&strcmp(str[n],"")!=0) { tree_add(str[n++]); } for(i=0;i<n;i++) { int l=strlen(str[i]); for(j=1;j<l;j++) { strcpy(left,str[i]); left[j]='\0'; strcpy(right,str[i]+j); if(tree_search(left)&&tree_search(right)) { puts(str[i]); break; } } } return 0;}
0 0
- HDU 1247 Hat’s Words(字典树)
- hdu 1247 字典树 Hat’s Words
- HDU 1247 Hat’s Words 字典树
- hdu 1247 Hat’s Words 字典树
- HDU 1247 Hat’s Words(字典树)
- hdu 1247 Hat’s Words(字典树)
- hdu 1247 Hat’s Words字典树
- hdu 1247 Hat’s Words(字典树)
- hdu 1247 Hat’s Words 字典树
- 【字典树】HDU 1247 Hat’s Words
- HDU--1247:Hat’s Words (字典树)
- hdu 1247 Hat’s Words(字典树)
- [字典树] HDU 1247 - Hat’s Words
- hdu 1247 Hat’s Words (字典树)
- HDU 1247 Hat’s Words 字典树
- HDU - 1247 Hat’s Words(字典树)
- hdu 1247 Hat’s Words 字典树
- hdu 1247 Hat’s Words(字典树)
- 杭电 2147
- NameNode跟secondarynamenode的执行过程
- 线段树(树状数组)hdu4267
- 奇异值分解
- CONFIG_IKCONFIG_PROC=y
- hdu 1247 Hat’s Words 字典树
- Cygwin编译自定义OpenCV库报错:opencv_contrib: LOCAL_SRC_FILES points to a missing file
- Android 开发尝试总结二:Android版HelloWorld项目文件结构分析
- 创建基于wicket的web项目(二)-常用控件
- UVA - 10474 Where is the Marble?
- (六)8天快速掌握Android视频教程_电话拨号器
- python的列表解析
- 深入Volley(一)volley缓存文件结构
- Linux Socket编程(不限Linux)