hdu 1075 字典树
#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 字典树的更多相关文章
- hdu 1075(字典树)
What Are You Talking About Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 102400/204800 K ...
- HDU 5687 字典树插入查找删除
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5687 2016百度之星资格赛C题,直接套用字典树,顺便巩固了一下自己对字典树的理解 #include< ...
- HDU 5384 字典树、AC自动机
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5384 用字典树.AC自动机两种做法都可以做 #include<stdio.h> #includ ...
- hdu 2112(字典树+最短路)
HDU Today Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu 2072(字典树模板,set,map均可做)
地址:http://acm.hdu.edu.cn/showproblem.php?pid=2072 lily的好朋友xiaoou333最近很空,他想了一件没有什么意义的事情,就是统计一篇文章里不同单词 ...
- Chip Factory HDU - 5536 字典树(删除节点|增加节点)
题意: t组样例,对于每一组样例第一行输入一个n,下面在输入n个数 你需要从这n个数里面找出来三个数(设为x,y,z),找出来(x+y)^z(同样也可以(y+z)^1)的最大值 ("^&qu ...
- hdu 1251 字典树的应用
这道题看了大神的模板,直接用字典树提交的会爆内存,用stl 里的map有简单有快 #include <iostream> #include <map> #include < ...
- hdu 2896 字典树解法
#include <iostream> #include <cstring> #include <cstdio> #include <cstdlib> ...
- Repository HDU - 2846 字典树
题意:给出很多很多很多很多个 单词 类似搜索引擎一下 输入一个单词 判断有一个字符串包含这个单词 思路:字典树变体,把每个单词的后缀都扔字典树里面,这里要注意dd是一个单词 但是把d 和dd都放字典树 ...
随机推荐
- iOS9 关于明文HTTP报错的修复方法
报错:App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. ...
- python vs java的rsa加密
首先:java的加密解密模块需要更加精细的算法细节指定 java的加密方式 javax.crypto.Cipher,定义的获取方式 tatic Cipher getInstance(String tr ...
- PostgreSQL 数据库错误状态编号解释[附带列表
PostgreSQL 服务器发出的所有消息都赋予了五个字符的错误代码, 这些代码遵循 SQL 的 "SQLSTATE" 代码的习惯.需要知道发生了什么错误条件的应用通常应该测试错误 ...
- 番茄花园Ghost Win10系统X64位10041装机版2015年4月
转载:系统妈,系统下载地址:http://www.xitongma.com/windows10/2015-04-01/6639.html 番茄花园Ghost Win10系统X64位10041装机版20 ...
- confluence的安装
参考链接:https://www.ilanni.com/?p=11989 一.什么是confluence confluence是一个专业的企业知识管理与协同软件,可以用于构建企业wiki.通过它可以实 ...
- nexus 搭建 maven 私服
nexus 搭建 maven 私服 本机环境 Win 8 JDK 7 Maven 3.2 Nexus 2.11 版本选择 http://www.sonatype.org/nexus/archivedn ...
- ansible相关说明
2.ansible相关说明 2.1.ansible相关命令 ansible:定义并运行简单任务,主要执行ad-hoc命令 ansible-config:查看.编辑.管理ansible配置 ansibl ...
- MySQL操作数据库和表的基本语句(DDL)
1.创建数据库: CREATE DATABASE 数据库名; eg.CREATE DATABASE test_ddl;2.创建表 CREATE TABLE 表名(列名 数据类型 约束,...); eg ...
- 除了上万的月薪之外,还有什么理由让我们必须学Python?
虽然目前的编程语言有很多,但是基础语法上的概念,本质上都是相通的.可以做到一通百通.所以没有必要为了学哪门语言纠结太多. python是目前市面上,我个人认为是最简洁&&最优雅& ...
- ArrayList中removeAll和clear的区别(无区别)
removeAll会直接调用此方法,传入list和false,因中间的逻辑都不会走(如果由retainAll方法调用,则会走这些逻辑判断),所以只需要看finaly中的最后一个if条件,w=0,通过循 ...