#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. java批处理、MySQL批处理

    e: cd MySQL\bin mysql -uroot -proot @pause MySQL批处理.bat e: cd JAVA\jdk1.8.0_77\bin javac Hello.java ...

  2. java单元测试注释执行顺序

    JUnit4通过注解的方式来识别测试方法.目前支持的主要注解有: @BeforeClass 全局只会执行一次,而且是第一个运行 @Before 在测试方法运行之前运行 @Test 测试方法 @Afte ...

  3. E. Dasha and Puzzle 数学题

    http://codeforces.com/contest/761/problem/E 给出一颗树,要求在坐标系中用平行于坐标轴的线描绘出来. 要求边不能相交,而且点的坐标唯一. 注意到2^1 + 2 ...

  4. 构建一个.net的干货类库,以便于快速的开发 - 验证码

    一个验证码对于一个网站的作用不言而喻,而随着技术的发展验证码的种类也开始多了起来,发展至今很多网站已经不再使用一种验证码,为满足需求程序猿就要写很多的方法来适应需求,今天我就来介绍我之前收集到的验证码 ...

  5. 外文翻译 《How we decide》赛场上的四分卫

    本书导言翻译 为了能看懂这一章,先做了如下的功课: 百度百科 四分卫 国家橄榄球联盟中文站 在2002年超级碗赛场上,比赛的时间仅剩80秒,两队比分持平.新英格兰爱国者队于17码的位置执球,他们的对手 ...

  6. BOW-js浏览器对象模型

  7. NavigationView的使用

    代码已经分享至github:https://github.com/YanYoJun/NavigationDemo 转载请注明原文链接:http://www.cnblogs.com/yanyojun/p ...

  8. leetcode_486. Predict the Winner

    https://leetcode.com/problems/predict-the-winner/ 题目描述:给定一个非负的积分数组,玩家1可以从数组两端任取一个积分,接着玩家2执行同样的操作,直至积 ...

  9. 阿里云服务器基本搭建_错误1_Permission denied (publickey)

    首先 修改这两个密码 然后重启服务器就可以了

  10. Spring工作原理及其作用

    1.springmvc请所有的请求都提交给DispatcherServlet,它会委托应用系统的其他模块负责负责对请求进行真正的处理工作. 2.DispatcherServlet查询一个或多个Hand ...