hdu-1247
来源:互联网 发布:金融it 编辑:程序博客网 时间:2024/05/20 16:01
思路:
字典树模板题
#include <iostream>#include <cstring>#include <cstdio>#define MAX 500007using namespace std;struct node{ int e; struct node* next[26];};node* root;char str[MAX][50];void Insert(char* s){ node* ptr = root; for(;*s != '\0';s++) { int n = *s-'a'; if(ptr->next[n] == NULL) ptr->next[n] = new node(); ptr = ptr->next[n]; } ptr->e = 1;}bool find2(char* s){ node* ptr = root; for(;*s != '\0';s++) { int n = *s-'a'; ptr = ptr->next[n]; if(ptr != NULL) { if(ptr->e==1 && *(s+1)=='\0') return true; } else return false; } return false;}bool find1(char* s){ node* ptr = root; for(;*s != '\0';s++) { int n = *s-'a'; ptr = ptr->next[n]; if(ptr->e==1 && find2(s+1)) return true; } return false;}int main(){ int i = 0; root = new node(); while(scanf("%s",str[i]) != EOF) { Insert(str[i]); i++; } for(int j = 0;j < i;j++) if(find1(str[j])) cout<<str[j]<<endl; return 0;}
0 0
- hdu 1247
- hdu 1247
- HDU 1247
- hdu 1247
- hdu 1247
- HDU 1247
- hdu 1247
- hdu 1247
- hdu-1247
- Hdu 1247
- hdu 1247
- HDU 1247 Trie树
- HDU-1247-Hats Words
- hdu 1247 字典树
- hdu 1247 字典树
- hdu 1247(字典树)
- hdu 1247 字典树
- HDU 1247 字典树
- 快速修改替换字符串工具ultraEdit
- hdu-1598
- hdu2444The Accomodation of Students
- Alljoyn瘦客户端库介绍
- 基础知识整理
- hdu-1247
- 指针和引用的参数传递
- hdu-1251
- iOS开发之数据存储
- hdu-2846 Repository
- 字符串的空格替换
- hdu-4287 Intelligent IME
- hdu-1800
- 动态规划中的0-1背包模型