字典树

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. C#基础知识系列六(静态类和静态类成员)

    静态类 静态类与非静态类基本相同,但存在一个区别:静态类不能实例化. 也就是说,不能使用 new 关键字创建静态类类型的变量. 因为没有实例变量,所以要使用类名本身访问静态类的成员. 例如,如果名为 ...

  2. FZU5BOYS-Beta版本冲刺计划及安排

    1.下一阶段需要改进完善的功能 话题模块(分类参考Citeulike论文网站),文章/计划的删除功能 2.下一阶段新增的功能 1)推荐模块(冷启动问题,拟爬取部分豆瓣数据,部分伪专家数据(我们团队), ...

  3. IntelliJ Idea13无法创建maven模板

    一.错误信息: -Dmaven.multiModuleProjectDirectory system property is not set. Check $M2_HOME environment v ...

  4. BACKBONE源代码解析

    //2014.11// Backbone.js 1.0.0 // (c) 2010-2013 Jeremy Ashkenas, DocumentCloud Inc. // Backbone may b ...

  5. 【Gym 100712B】Rock-Paper-Scissors

    题 题意 对给定的对手的出拳顺序,如果只能按几个R,然后几个P,再几个S的顺序出拳(几个也可以是0个),那么求赢的方法有多少种. 分析 我原来想枚举P开始的位置和S开始的位置然后算得分,但是超时了o( ...

  6. 判断一个数据是否存在于一个表中,Oracle中写自定义函数

    create or replace function isExist(data in DataTypes) --DataTypes 为表中该数据的类型return Numberisv_flag num ...

  7. 【bzoj1486】 HNOI2009—最小圈

    http://www.lydsy.com/JudgeOnline/problem.php?id=1486 (题目链接) 题意 给出一张有向图,规定一个数值u表示图中一个环的权值/环中节点个数.求最小的 ...

  8. POJ1089 Intervals

    Description There is given the series of n closed intervals [ai; bi], where i=1,2,...,n. The sum of ...

  9. POJ1459Power Network(dinic模板)

    Power Network Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 25832   Accepted: 13481 D ...

  10. boost库(条件变量)

    1相关理念 (1)类名 条件变量和互斥变量都是boost库中被封装的类. (2)条件变量 条件变量是thread库提供的一种等待线程同步的机制,可实现线程间的通信,它必须与互斥量配合使用,等待另一个线 ...