POJ2001 Shortest Prefixes(字典树)
来源:互联网 发布:如何爬取网页的js脚本 编辑:程序博客网 时间:2024/06/05 12:49
Shortest Prefixes
题目链接:
http://poj.org/problem?id=2001
解题思路:
字典树模板!!!
AC代码:
#include <iostream>#include <cstdio>#include <cstring>using namespace std;struct node{ int cnt; struct node *next[26]; node(){ cnt = 0; memset(next,0,sizeof(next)); }};node *root = NULL;char str[1010][21];void build(char *s){ node *p = root,*tmp; int l = strlen(s); for(int i = 0; i < l; i++){ if(p->next[s[i]-'a'] == NULL){ tmp = new node; p->next[s[i]-'a'] = tmp; } p = p->next[s[i]-'a']; p->cnt++; }}void findtrie(char *s){ node *p = root; int l = strlen(s); for(int i = 0; i < l; i++){ printf("%c",s[i]); p = p->next[s[i]-'a']; if(p->cnt == 1) break; } printf("\n");}int main(){ root = new node; int num = 0; while(scanf("%s",str[num++]) != EOF) build(str[num-1]); for(int i = 0; i < num; i++){ printf("%s ",str[i]); findtrie(str[i]); } return 0;}
0 0
- POJ2001 Shortest Prefixes(字典树)
- POJ2001 - Shortest Prefixes - 字典树
- POJ2001 Shortest Prefixes【字典树】
- 【poj2001】Shortest Prefixes 字典树
- POJ2001 Shortest Prefixes(字典树)
- [复习][poj2001]字典树(trie树)Shortest Prefixes
- kyeremal-poj2001-Shortest Prefixes-字典树trie
- POJ2001 Shortest Prefixes 动态字典树实现
- Shortest Prefixes(poj2001,tire树)
- 字典树trie树 模板题 POJ2001 Shortest Prefixes
- poj2001 Shortest Prefixes (trie树)
- poj2001 Shortest Prefixes trie树
- 【Trie树】POJ2001 Shortest Prefixes
- Shortest Prefixes(字典树)
- Shortest Prefixes(字典树)
- Shortest Prefixes(字典树)
- POJ2001——Shortest Prefixes(Trie树模板)
- POJ2001 Shortest Prefixes trie树模板
- 使用U盘模拟软盘
- HDU 1060 Leftmost Digit (数论)
- pat1067 考察了逆向思维
- 多态 ,
- 笔记3_看张鹏老师html+css视频所得
- POJ2001 Shortest Prefixes(字典树)
- Sicily 1093 Air Express
- UVA - 10594 Data Flow (最小费用最大流)
- acm
- NSString的一些用法
- UIKeyBoard高度的监控
- 汇编中的pc的意思
- book list and concept list
- hackerrank_Chocolate Game