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 ...
随机推荐
- [C#基础]ref和out的区别
在C#中通过使用方法来获取返回值时,通常只能得到一个返回值.因此,当一个方法需要返回多个值的时候,就需要用到ref和out,那么这两个方法区别在哪儿呢? MSDN: ref 关键字使参数按 ...
- Bootstrap3.0学习第十八轮(JavaScript插件——下拉菜单)
详情请查看 http://aehyok.com/Blog/Detail/25.html 个人网站地址:aehyok.com QQ 技术群号:206058845,验证码为:aehyok 本文文章链接:h ...
- __weak typeof(self) weakSelf = self
typeof(self) 是获取到self的类型,这样定义出的weakSelf就是和self一个类型的, 加上__weak是建立一个若引用,整句就是给self定义了一个若引用性质的替身;这个一般用在使 ...
- java中的字符串简介,字符串的优化以及如何高效率的使用字符串
简介 String最为java中最重要的数据类型.字符串是软件开发中最重要的对象之一,通常,字符串对象在内存中总是占据着最大的空间块.所以,高效处理字符串,将提高系统的整个性能. 在java语言中,S ...
- ssh开发流程
- C语言浮点数除法可以精确到多少位小数
double型的两个数相除,得到的浮点数能精确到多少位呢..用我家电脑做了个实验,编译器是Code::Blocks 13.12. 然后用电脑自带的计算器算的结果和C语言算的结果比较如图. 第一例里a= ...
- Python 之我见
读音 Python(KK 英语发音:/ˈpaɪθən/) 序言 其实早前就已经接触了python这个功能强大的脚本语言,但是那时只是基于兴趣而学习,目的性并不是很强,所以学习的并不是很深入.最近由于闲 ...
- 打印cell的视图层次结构
#ifdef DEBUG NSLog(@"Cell recursive description:\n\n%@\n\n", [cell performSelector:@select ...
- python:open文件操作
file: jim|123|1 tom|321|3 kamil|432|1 # __author__ = liukun # coding:utf-8 obj = open('file.txt','r' ...
- POJ1979 Red and Black
速刷一道DFS Description There is a rectangular room, covered with square tiles. Each tile is colored eit ...