字典树

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. sublime text下代码太长brackethighlighter不能正确显示闭合高亮的解决方法

    用brackethighlighter显示高亮一直都有这个问题...也没在网上找到解决方案,就一直凑合着用,今天翻着配置文件玩,改了参数发现问题解决了...... 修改search_threshold ...

  2. 在Web Service中傳送Dictionary

    有個需求,想在Web Service中傳遞Dictionary<string, string>參數,例如: 排版顯示純文字 [WebMethod] public Dictionary< ...

  3. Spring-MVC流程图

    Spring MVC工作流程图 图一 图二  Spring工作流程描述       1. 用户向服务器发送请求,请求被Spring 前端控制Servelt DispatcherServlet捕获:   ...

  4. 【CodeForces 621C】Wet Shark and Flowers

    题 There are n sharks who grow flowers for Wet Shark. They are all sitting around the table, such tha ...

  5. springMVC实现防止重复提交

    参考文档:http://my.oschina.net/mushui/blog/143397

  6. poj 3233 矩阵快速幂+YY

    题意:给你矩阵A,求S=A+A^1+A^2+...+A^n sol:直接把每一项解出来显然是不行的,也没必要. 我们可以YY一个矩阵: 其中1表示单位矩阵 然后容易得到: 可以看出这个分块矩阵的左下角 ...

  7. Jquery,ajax返回json数据后呈现到html页面的$.post方式。

    ------------------------------------------------------完整版------------------------------------------- ...

  8. 锋利的jQuery-2--判断jQuery获取到的对象是否存在$().length

    1.使用js获取不存在的对象: document.getElementById("tt").style.color = "red"; 如果网页中不存在id = ...

  9. Openresty 与 Tengine

    Openresty 与 Tengine Openresty和Tengine基于 Nginx 的两个衍生版本,某种意义上他们都和淘宝有关系,前者是前淘宝工程师agentzh主导开发的,后者是淘宝的一个开 ...

  10. Apache22中配置虚拟主机(Apache VirtualHost)

    Apache VirtualHost的作用就是可以让一个apache为多个域名服务,相当于一个服务器挂了N多个网站,举个例子: 我的apache服务器,ip为x.x.x.x,我有两个域名www.too ...