字典树

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的更多相关文章

  1. HDOJ.1075 What Are You Talking About(map)

    What Are You Talking About 点我跳转到题面 点我一起学习STL-MAP 题意分析 首先第一组START-END给出翻译的字典,第二组START-END给出一句话,查找里面出现 ...

  2. 【HDOJ】1075 What Are You Talking About

    map,STL搞定. #include <iostream> #include <string> #include <cstdio> #include <cs ...

  3. 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 ...

  4. 杭电hdoj题目分类

    HDOJ 题目分类 //分类不是绝对的 //"*" 表示好题,需要多次回味 //"?"表示结论是正确的,但还停留在模块阶 段,需要理解,证明. //简单题看到就 ...

  5. HDOJ 题目分类

    HDOJ 题目分类 /* * 一:简单题 */ 1000:    入门用:1001:    用高斯求和公式要防溢出1004:1012:1013:    对9取余好了1017:1021:1027:   ...

  6. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  7. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  8. HDOJ 1326. Box of Bricks 纯水题

    Box of Bricks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  9. HDOJ 1004 Let the Balloon Rise

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

随机推荐

  1. 5、面向对象以及winform的简单运用(方法重载、隐藏、重写与虚方法)

    方法的重载: 规定一个方法可以具有不同的实现,但方法的名称是相同的.如: //同样是Man这个方法 public int Man(int age,int name) { …… } //重载 publi ...

  2. Bootstrap3.0学习第八轮(工具Class)

    详情请查看http://aehyok.com/Blog/Detail/14.html 个人网站地址:aehyok.com QQ 技术群号:206058845,验证码为:aehyok 本文文章链接:ht ...

  3. G-nav-01

    <body><header id="masthead" class="masthead" role="banner"> ...

  4. iOS边练边学--cocoaPods管理第三方框架--命令行方式实现

    更换源 Gem是一个管理Ruby库和程序的标准包,它通过Ruby Gem(如 http://rubygems.org/)源来查找.安装.升级和写在软件包 gem sources --remove ht ...

  5. js 选项卡实现

    <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8&quo ...

  6. Yii2结合webuploader实现图片上传

    js中 uploader = WebUploader.create({ // 自动上传. auto : true, // swf文件路径 swf : 'webuploader/Uploader.swf ...

  7. CRUD之delete操作

    在公司的项目中delete之后的操作有两种处理方式 1.后台删除成功之后前台页面刷新 2.后台删除成功之后页面不刷新,但是数据所在的那个div会刷新一次 3.后台删除,页面上做了一个删除,删除的td没 ...

  8. [转]ubuntu安装光盘修复grub-rescue引导失败问题

    Reference:http://liujianqiao398.blog.163.com/blog/static/181827257201292775649815/ 1.步骤一 以试用方式进入ubun ...

  9. 洛谷P1417 烹调方案

    题目背景 由于你的帮助,火星只遭受了最小的损失.但gw懒得重建家园了,就造了一艘飞船飞向遥远的earth星.不过飞船飞到一半,gw发现了一个很严重的问题:肚子饿了~ gw还是会做饭的,于是拿出了储藏的 ...

  10. wifi与wimax

    这几天在看文献中看到802.11a,802.11n和802.16e这几种无信通信协议标准,在网上查了相关资料后,看到有个帖子总结得不错,故将其转载过来. 转:http://blog.csdn.net/ ...