hdu1247 hat's words
来源:互联网 发布:链传动计算软件 编辑:程序博客网 时间:2024/06/06 04:02
Hat’s Words
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64uDescription
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
貌似没啥区别==而且一组数组也不用del()
#include <iostream>#include<iostream>#include<cstring>#include<cstdlib>#include<cstdio>using namespace std;typedef struct Trie_node{int count; // 统计单词前缀出现的次数struct Trie_node* next[26]; // 指向各个子树的指针bool exist; // 标记该结点处是否构成单词}TrieNode , *Trie;TrieNode* createTrieNode(){TrieNode* node = (TrieNode *)malloc(sizeof(TrieNode));node->count = 0;node->exist = false;memset(node->next , 0 , sizeof(node->next)); // 初始化为空指针return node;}void Trie_insert(Trie root, char* word){Trie node = root;char *p = word;int id;while( *p ){id = *p - 'a';if(node->next[id] == NULL){node->next[id] = createTrieNode();}node = node->next[id]; // 每插入一步,相当于有一个新串经过,指针向下移动++p;node->count += 1; // 这行代码用于统计每个单词前缀出现的次数(也包括统计每个单词出现的次数)}node->exist = true; // 单词结束的地方标记此处可以构成一个单词}bool Trie_search(Trie root, char* word){Trie node = root;char *p = word;int id;while( *p ){id = *p - 'a';node = node->next[id];++p;if(node == NULL)return 0;}if(node->exist) // 查找成功 return 1; return 0;}char s[50000][100];int main(){ // freopen("cin.txt","r",stdin); int i=0; Trie root = createTrieNode(); while(scanf("%s",s[i])!=EOF) { Trie_insert(root , s[i++]); } for(int k=0;k<i;k++) { for(int j=1;j<strlen(s[k])-1;j++) { char s1[100],s2[100]; for(int jj=0;jj<j;jj++) s1[jj]=s[k][jj]; s1[j]='\0'; strcpy(s2,s[k]+j); if(Trie_search(root,s1)&&Trie_search(root,s2)) { printf("%s\n",s[k]); break; } } } return 0;}
0 0
- hdu1247 Hat’s Words
- HDU1247 Hat’s Words
- hdu1247 Hat’s Words
- hdu1247 hat's words
- hdu1247 Hat’s Words
- hdu1247 Hat’s Words
- hdu1247 Hat’s Words
- hash hdu1247 Hat’s Words
- HDU1247 Hat’s Words【Trie】
- Hat's Words hdu1247 trie
- 【字典树】 hdu1247 Hat’s Words
- Hat’s Words hdu1247 字典树+搜索
- HDU1247-Hat’s Words(字典树)
- Hat’s Words(hdu1247字典树)
- hdu1247 Hat’s Words (字典树)
- hdu1247 Hat’s Words(字典树)
- HDU1247-Hat’s Words(trie树)
- HDU1247 Hat’s Words 【trie树】
- CodeForces 5B - Center Alignment
- postgresql 查数据库总大小(占用磁盘空间)
- Java之Servlet
- 将对象里属性值相同的元素放到同一容器里
- 时钟体系
- hdu1247 hat's words
- 实战Memcached缓存系统(1)Memcached基础及示例程序
- 27个提升效率的iOS开源库推荐
- 优化Apache,提高并发
- Hibernate对象三种状态(转自xiaoluo501395377)
- unity 自制小荷花
- UITabBarController — 标签视图控制器
- ExtJS 的一些使用总结(适用于3.x版本)——第三弹
- 学习JAVA框架的心得体会