#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
#include<stack>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
struct Node
{
int c;
int next[];
} node[];
int cnt;
int newnode()
{
++cnt;
node[cnt].c=;
for(int i=; i<; i++)
node[cnt].next[i]=-;
return cnt;
}
char s[][];
int len[];
void insert(int rt,int tt,int now)
{
if(now>len[tt])return;
int p=s[tt][now]-'a'; if(node[rt].next[p]==-)
{
int l=newnode();
node[rt].next[p]=l;
node[l].c+=; insert(l,tt,now+);
}
else
{
int l=node[rt].next[p];
node[l].c+=; insert(l,tt,now+);
}
}
void print(int rt,int tt,int now)
{
if(now>len[tt])return;
printf("%c",s[tt][now]);
if(node[rt].c==)return;
int p=s[tt][now+]-'a';
print(node[rt].next[p],tt,now+);
}
int main()
{
int k=;
cnt=;
node[].c=;
for(int i=;i<;i++)
node[].next[i]=-;
while(~scanf("%s",s[++k]+))
{
len[k]=strlen(s[k]+);
insert(,k,); }
for(int i=;i<=k;++i)
{
printf("%s ",s[i]+);
int p=s[i][]-'a';
print(node[].next[p],i,);
printf("\n");
}
return ;
}

POJ 2001 字典树(入门题)的更多相关文章

  1. hdu 1251 统计难题 (字典树入门题)

    /******************************************************* 题目: 统计难题 (hdu 1251) 链接: http://acm.hdu.edu. ...

  2. HDU 4825 Xor Sum(01字典树入门题)

    http://acm.hdu.edu.cn/showproblem.php?pid=4825 题意: 给出一些数,然后给出多个询问,每个询问要从之前给出的数中选择异或起来后值最大的数. 思路:将给出的 ...

  3. HDU 1251 统计难题(字典树模板题)

    http://acm.hdu.edu.cn/showproblem.php?pid=1251 题意:给出一些单词,然后有多次询问,每次输出以该单词为前缀的单词的数量. 思路: 字典树入门题. #inc ...

  4. POJ 2503 字典树

    题目链接:http://poj.org/problem?id=2503 题意:给定一个词典,输入格式为[string1' 'string2]  意思是string2的值为string1. 然后给定一波 ...

  5. 字典树模板题(统计难题 HDU - 1251)

    https://vjudge.net/problem/HDU-1251 标准的字典树模板题: 也注意一下输入方法: #include<iostream> #include<cstdi ...

  6. CH 1601 - 前缀统计 - [字典树模板题]

    题目链接:传送门 描述给定 $N$ 个字符串 $S_1,S_2,\cdots,S_N$,接下来进行 $M$ 次询问,每次询问给定一个字符串 $T$,求 $S_1 \sim S_N$ 中有多少个字符串是 ...

  7. hdu1305 字典树水题

    题意:      给你一些字符串,然后问你他们中有没有一个串是另一个串的前缀. 思路:       字典树水题,(这种水题如果数据不大(这个题目不知道大不大,题目没说估计不大),hash下也行,把每个 ...

  8. HDU 1251 统计难题(字典树入门模板题 很重要)

    统计难题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others)Total Submi ...

  9. POJ 1451 T9 (字典树好题)

    背景:为了方便九宫格手机用户发短信,希望在用户按键时,根据提供的字典(给出字符串和频数),给出各个阶段最有可能要打的单词. 题意: 首先给出的是字典,每个单词有一个出现频率.然后给出的是询问,每个询问 ...

随机推荐

  1. angular service/directive

    <html class=" js cssanimations csstransitions" ng-app="phonecatApp" > < ...

  2. shell复习笔记----用户管理

    $ who    可以知道系统上有多少登陆 $who |wc -l 计算用户个数 注意:|是管道符号,可以在两个程序之间建立管道(pipeline):who 的输出,成了 wc 的输入, wc 所列出 ...

  3. JPA2 关于 PagingAndSortingRepository

    And --- 等价于 SQL 中的 and 关键字,比如 findByUsernameAndPassword(String user, Striang pwd): Or --- 等价于 SQL 中的 ...

  4. Linux下使用GDB调试程序

    问题描述:          Linux下使用GDB调试程序 问题解决:          (1)生成调试文件 注:         使用命令   gdb IOStream.c   -o IOStre ...

  5. JS中如何定义全局变量

    三种方法 1.在js的function外定义一个变量 var name='测试'; function XX(){        alert(name); } 2.不使用var,直接给定义变量,隐式的声 ...

  6. poj 3318 Matrix Multiplication 随机化算法

    方法1:暴力法 矩阵乘法+优化可以卡时间过的. 方法2:随机化 随机构造向量x[1..n],则有xAB=xC;这样可以将小运算至O(n^2). 代码如下: #include<iostream&g ...

  7. samba配置smb.conf

    [share]      path = /home/phinecos/share      available = yes      browsealbe = yes      public = ye ...

  8. js 中map的几种实现方式

    简单使用 1, 通过对象方式: var myHash = {}; myHash["deviceID"] = "HY_000001"; myHash[" ...

  9. 不同VLAN之间互相通信

    前话 我们经常到机房上课,想必对机房后面那层叠的跟DVD一样的机器有印象吧,那些就是交换机. 交换机作用是什么? 我这里度娘一下: 交换机(Switch)意为"开关"是一种用于电( ...

  10. javascript高级程序设计读书笔记

    第2章  在html中使用javascript 一般都会把js引用文件放在</body>前面,而不是放在<head>里, 目的是最后读取js文件以提高网页载入速度. 引用js文 ...