#include<stdio.h>

#include<iostream>

struct node {

int num,i;

node *a[27];

char s[20];//定义局部不是空的

node() {

num=0;

for(i=0;i<26;i++)

a[i]=NULL;

}

}*root;

char s2[20],str[20],str1[3100],s1[20],h[20];

void insert(int len ,node *root) {

int i;

for(i=0;i<len;i++) {

if(root->a[s1[i]-'a']==NULL) 

root->a[s1[i]-'a']=new node();

root=root->a[s1[i]-'a'];

}

root->num=1;

     strcpy(root->s,s2);

return ;

}

void find (int len,node *root) {

int i;

for(i=0;i<len;i++) {

root=root->a[str[i]-'a'];

if(root==NULL)

            return ;

}

if(root->num==1)//必须判断是否存在

strcpy(h,root->s);

return;

}

void del(node *root) {

int i;

for(i=0;i<26;i++)

if(root->a[i]!=NULL)

del(root->a[i]);

delete root;

}

int main() {

int i,k;

root=new node();

        scanf("%s",str);

while(scanf("%s",s2),strcmp(s2,"END")) {

scanf("%s",s1);

insert(strlen(s1),root);

}

     scanf("%s",str);

getchar();

while(gets(str1),strcmp(str1,"END")) {

k=0;h[0]=0;

for(i=0;str1[i];i++) {

if(str1[i]>='a'&&str1[i]<='z')

str[k++]=str1[i];

else {

if(k==0) {

printf("%c",str1[i]);

continue;

}

str[k]=0;

find(strlen(str),root);

if(strlen(h)==0)

printf("%s",str);

else

printf("%s",h);

k=0;

h[0]=0;

printf("%c",str1[i]);

}

}

str[k]=0;

find(strlen(str),root);

if(strlen(h)==0)

printf("%s",str);

else

printf("%s",h);

printf("\n");

}

del(root);

return 0;

}

hdu 1075 字典树的更多相关文章

  1. hdu 1075(字典树)

    What Are You Talking About Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/204800 K ...

  2. HDU 5687 字典树插入查找删除

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=5687 2016百度之星资格赛C题,直接套用字典树,顺便巩固了一下自己对字典树的理解 #include< ...

  3. HDU 5384 字典树、AC自动机

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=5384 用字典树.AC自动机两种做法都可以做 #include<stdio.h> #includ ...

  4. hdu 2112(字典树+最短路)

    HDU Today Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  5. hdu 2072(字典树模板,set,map均可做)

    地址:http://acm.hdu.edu.cn/showproblem.php?pid=2072 lily的好朋友xiaoou333最近很空,他想了一件没有什么意义的事情,就是统计一篇文章里不同单词 ...

  6. Chip Factory HDU - 5536 字典树(删除节点|增加节点)

    题意: t组样例,对于每一组样例第一行输入一个n,下面在输入n个数 你需要从这n个数里面找出来三个数(设为x,y,z),找出来(x+y)^z(同样也可以(y+z)^1)的最大值 ("^&qu ...

  7. hdu 1251 字典树的应用

    这道题看了大神的模板,直接用字典树提交的会爆内存,用stl 里的map有简单有快 #include <iostream> #include <map> #include < ...

  8. hdu 2896 字典树解法

    #include <iostream> #include <cstring> #include <cstdio> #include <cstdlib> ...

  9. Repository HDU - 2846 字典树

    题意:给出很多很多很多很多个 单词 类似搜索引擎一下 输入一个单词 判断有一个字符串包含这个单词 思路:字典树变体,把每个单词的后缀都扔字典树里面,这里要注意dd是一个单词 但是把d 和dd都放字典树 ...

随机推荐

  1. Windows查杀端口

    Windows环境下当某个端口被占用时,通过netstat命令进行查询pid,然后通过taskkill命令杀进程. 一.查询占用端口号的进程信息 netstat -an|findstr 二.杀掉占用端 ...

  2. iOS 实现复选框 checkbox --转

    转自:http://www.cnblogs.com/ygm900/p/3468891.html  -(void)checkboxClick:(UIButton *)btn{    btn.select ...

  3. [转]Asp.net Mvc2中重构View的三种方式

    本文转自:http://www.cnblogs.com/zhuqil/archive/2010/07/14/asp-net-mvc2-view-refactoring.html 我们在Asp.net ...

  4. Effective Java读书笔记完结啦

    Effective Java是一本经典的书, 很实用的Java进阶读物, 提供了各个方面的best practices. 最近终于做完了Effective Java的读书笔记, 发布出来与大家共享. ...

  5. P1603 斯诺登的密码

    题目背景 根据斯诺登事件出的一道水题 题目描述 题目描述 2013年X月X日,俄罗斯办理了斯诺登的护照,于是他混迹于一架开往委内瑞拉的飞机.但是,这件事情太不周密了,因为FBI的间谍早已获悉他的具体位 ...

  6. ReactJS-2-props vs state

    rops理解: 大多数组件都可以在创建的时候被不同的参数定制化,这些不同的参数就叫做props.props的流向是父组件到子组件. 子组件Comment,是一条评论组件,父组件CommentList, ...

  7. UI动画效果

    UI界面的动画效果总结 方式1:头尾式 //开始动画 [UIView beginAnimations:nil context:nil]; //设置动画时间 [UIView setAnimationDu ...

  8. asp.net 实现treeview 选中父节点其子节点也选种中 选中子节点其父节点与根节点也被选中

    1.在 Page_Load(object sender, EventArgs e) 里面加入: TreeView1.Attributes.Add("onclick", " ...

  9. 微信小程序中的图形验证码

    可以在utils中新建一个mcaptcha.js 代码如下: module.exports = class Mcaptcha { constructor(options) { this.options ...

  10. [转]c++应用程序文件的编译过程

    原文地址 这里讲下C++文件的编译过程及其中模板的编译过程: 一:一般的C++应用程序的编译过程.    一般说来,C++应用程序的编译过程分为三个阶段.模板也是一样的. 在cpp文件中展开inclu ...