HDOJ 1075
字典树
| 9890974 | 2013-12-25 15:31:06 | Accepted | 1075 | 468MS | 59832K | 1342 B | G++ | 泽泽 |
#include<stdio.h>
#include<cstring>
#include<cstdlib>
struct node
{
node *next[];
int key;
char ans_s[];
}root;
void insert(char *str,char *s)
{
int len=strlen(str);
node *p=&root,*q;
for(int i=;i<len;i++)
{
int id=str[i]-'a';
if(p->next[id]==NULL)
{
q=(node *)malloc(sizeof(root));
q->key=;
for(int j=;j<;j++)
q->next[j]=NULL;
p->next[id]=q;
p=p->next[id];
}
else
p=p->next[id];
}
if(p->key!=-)
{
strcpy(p->ans_s,s);
p->key=-;
}
}
void find(char *str)
{
int len=strlen(str);
node *p=&root;
for(int i=;i<len;i++)
{
int id=str[i]-'a';
if(p->next[id]==NULL)
{
printf("%s",str);
return ;
}
else
{
p=p->next[id];
}
}
if(p->key==-)
printf("%s",p->ans_s);
else
printf("%s",str);
return; }
int main()
{
int i;
char s1[],s2[],s[];
for(i=;i<;i++)
root.next[i]=NULL;
scanf("%s",s1);
while(scanf("%s",s1)!=EOF&&strcmp(s1,"END")!=)
{
scanf("%s",s2);
insert(s2,s1);
}
scanf("%s",s1);
getchar();
while(gets(s)&&strcmp(s,"END")!=)
{
int k=,len=strlen(s);
for(i=;i<len;i++)
{
while(s[i]>='a'&&s[i]<='z')//满足是字母,wa了一次
{
s2[k++]=s[i++];
}
s2[k]='\0';
k=;
find(s2);
printf("%c",s[i]);
}
printf("\n");
} return ;
}
HDOJ 1075的更多相关文章
- HDOJ.1075 What Are You Talking About(map)
What Are You Talking About 点我跳转到题面 点我一起学习STL-MAP 题意分析 首先第一组START-END给出翻译的字典,第二组START-END给出一句话,查找里面出现 ...
- 【HDOJ】1075 What Are You Talking About
map,STL搞定. #include <iostream> #include <string> #include <cstdio> #include <cs ...
- HDOJ/HDU 1075 What Are You Talking About(字符串查找翻译~Map)
Problem Description Ignatius is so lucky that he met a Martian yesterday. But he didn't know the lan ...
- 杭电hdoj题目分类
HDOJ 题目分类 //分类不是绝对的 //"*" 表示好题,需要多次回味 //"?"表示结论是正确的,但还停留在模块阶 段,需要理解,证明. //简单题看到就 ...
- HDOJ 题目分类
HDOJ 题目分类 /* * 一:简单题 */ 1000: 入门用:1001: 用高斯求和公式要防溢出1004:1012:1013: 对9取余好了1017:1021:1027: ...
- HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- HDOJ 1326. Box of Bricks 纯水题
Box of Bricks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDOJ 1004 Let the Balloon Rise
Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...
随机推荐
- 01.C#数据类型、排序、过滤(一章1.1-1.2)
随着看的文章及探讨越多,越发现自己实在太不定性了,看下<C#深入理解>吧,做一下读书笔记,从中发现自己的不足.闲话不说,进入正题吧. 在C#1中定下一个简单的数据类型 public cla ...
- javascript继承(八)-封装
这个系列主要探讨的是javascript面向对象的编程,前面已经着重介绍了一下js的继承,下面想简单的说一下js如何实现封装的特性. 我们知道面向对象的语言实现封装是把成员变量和方法用一个类包围起来, ...
- 第四章:Javascript表达式和运算符
表达式是javascript中的一个短语,javascript解释器会将其计算出一个结果.程序中常用量是最简单的一类表达式就是变量.变量名也是一种简单的表达式,它的值就是赋值给变量的值.复杂的表达式是 ...
- AngularJS - 快速入门
刚开始接触时总是去wiki或各种百科以了解一番. 它们会告诉我一些MVVM.双向数据绑定.依赖注入等等名词,觉得这些名词好上档次,然后我很可能就不打算用这个东西了. AngularJS是什么? 完全使 ...
- 【团队项目演示】FZU5BOYS之团队项目链接汇总
FZU5BOYS 项目冲刺之博客汇总 Alpha版本 Day One Day Two Day Three Day Four Day Five Day Six Day Seven Day Ei ...
- 【codevs 1296】营业额统计 水~~
今天下午先写一个Splay水题来复习一下Splay模板.是不是有点太水了做这种水题我有点良心不安. 可笑的是一开始我竟然WA了一组,看来是我低估水题的数据范围了,我是空节点直接返回inf或-inf,明 ...
- ZOJ 3201 树形dp+背包(简单题)
#include<cstdio> #include<vector> #include<cstring> #include<iostream> using ...
- hdu2923 最短路floyd
建图还是有点烦人的. #include<map> #include<string> #include<stdio.h> #include<iostream&g ...
- POJ1364 King
Description Once, in one kingdom, there was a queen and that queen was expecting a baby. The queen p ...
- DRUPAL-PSA-CORE-2014-005 && CVE-2014-3704 Drupal 7.31 SQL Injection Vulnerability /includes/database/database.inc Analysis
目录 . 漏洞描述 . 漏洞触发条件 . 漏洞影响范围 . 漏洞代码分析 . 防御方法 . 攻防思考 1. 漏洞描述 Use Drupal to build everything from perso ...