hdu--1247--Hat’s Words(一般)
来源:互联网 发布:insar数据下载 编辑:程序博客网 时间:2024/05/16 23:02
Hat’s Words
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5772 Accepted Submission(s): 2154
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<iostream>#include<cstring>#include<cstdio>using namespace std;const int MAXN=26;const int MAX=50005;char word[MAX][27];struct node{ bool is; node *next[MAXN]; node() { is=false; memset(next,0,sizeof(next)); }};void Insert(node *rt,char *s){ int i=0; node *p=rt; while(s[i]) { int k=s[i++]-'a'; if(p->next[k]==NULL) p->next[k]=new node(); p=p->next[k]; } p->is=true; //该结点是单词的尾}bool Search(node *rt,char s[]){int i=0,top=0,stack[1000];node *p=rt;while(s[i]){int k=s[i++]-'a';if(p->next[k]==NULL) return 0;p=p->next[k];if(p->is && s[i])//找到该单词含有子单词的分割点 stack[top++]=i;//入栈}while(top)//从可能的分割点去找{ bool ok=1;i=stack[--top];p=rt;while(s[i]){int k=s[i++]-'a';if(p->next[k]==NULL){ok=false;break;}p=p->next[k];}if(ok && p->is)//找到最后,并且是单词的return 1;}return 0;}int main(){ int i=0; node *rt=new node(); while(gets(word[i])) { Insert(rt,word[i]); i++;}for(int j=0;j<i;j++)if(Search(rt,word[j])) printf("%s\n",word[j]); return 0;}
- hdu--1247--Hat’s Words(一般)
- HDU 1247-Hat’s Words(set)
- HDU 1247 Hat's words(Trie)
- hdu 1247 Hat’s Words(Trie)
- HDU 1247 Hat’s Words (Trie)
- 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
- u-boot下运行led测试测程序
- gstreamer 手册
- poj1273 Drainage Ditches 最大流EK
- document.getElementsByClassName的理想实现
- hdu 4576 Robot 杭州邀请赛第一题
- hdu--1247--Hat’s Words(一般)
- android 简析自定义布局、布局的执行流程
- 黑马程序员_高新技术之代理
- 曲线拟合和插值的区别
- Android 异步加载解决方案
- android 开发环境搭建
- 设置QPushButton的背景图片
- 基于文件过滤驱动的透明加密那点事儿
- windows8开发学习笔记