HDU 1247 Hat’s Words
来源:互联网 发布:mac文明5控制台 编辑:程序博客网 时间:2024/05/24 15:42
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<stdio.h>#include<string.h>int ch[7000010][26];int val[7000010] ,sz=1;char s[50005][50];char a[50] ,b[50];int id(char c) {return c-'a';}void Inser(char *s) { int u=0; for(int i=0;s[i];i++) { int c=id(s[i]); if(!ch[u][c]) ch[u][c]=sz++; u=ch[u][c]; } val[u]=1;}int Find(char *s ){ int u=0; for(int i=0;s[i];i++) { int c=id(s[i]); if(!ch[u][c]) return 0; u=ch[u][c]; } if(val[u] == 1) return 1; else return 0;}int main(){ int k=0; while(~scanf("%s",s[k])) { Inser(s[k]); k++; } for(int i=0;i<k;i++) { int n=strlen(s[i]); for(int j=0; j<n-1 ;j++) { memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); int kk=0 ,aa ,bb; for(aa=0;aa<=j;aa++) a[aa]=s[i][aa]; for(bb=j+1;bb<n;bb++) b[kk++]=s[i][bb]; if(Find(a) && Find(b)) { puts(s[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 Hat's Words(1247)
- HDU 1247 Hat’s Words
- HDU 1247 Hat’s Words
- hdu 1247 Hat’s Words
- 面试题整理(三)
- cookie路径和域
- 伪随机数
- 堆排序
- 面试题整理(四)
- HDU 1247 Hat’s Words
- Twitter实时搜索系统EarlyBird
- tomcat jndi + spring配置
- Java提高篇(二八)------TreeSet
- DataGridView控件选中单元格、直接在控件中修改信息
- ubuntu中JK + Apache 2.x + Tomcat 7实现群集完整过程
- Welcome to XTCPC
- 黑马程序员---享元设计模式Flyweight
- xtuoj-grid