What Are You Talking About

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/204800 K (Java/Others)
Total Submission(s): 11730    Accepted Submission(s): 3763

Problem Description
Ignatius is so lucky that he met a Martian yesterday. But he didn't know the language the Martians use. The Martian gives him a history book of Mars and a dictionary when it leaves. Now Ignatius want to translate the history book into English. Can you help him?
 
Input
The problem has only one test case, the test case consists of two parts, the dictionary part and the book part. The dictionary part starts with a single line contains a string "START", this string should be ignored, then some lines follow, each line contains two strings, the first one is a word in English, the second one is the corresponding word in Martian's language. A line with a single string "END" indicates the end of the directory part, and this string should be ignored. The book part starts with a single line contains a string "START", this string should be ignored, then an article written in Martian's language. You should translate the article into English with the dictionary. If you find the word in the dictionary you should translate it and write the new word into your translation, if you can't find the word in the dictionary you do not have to translate it, and just copy the old word to your translation. Space(' '), tab('\t'), enter('\n') and all the punctuation should not be translated. A line with a single string "END" indicates the end of the book part, and that's also the end of the input. All the words are in the lowercase, and each word will contain at most 10 characters, and each line will contain at most 3000 characters.
 
Output
In this problem, you have to output the translation of the history book.
 
Sample Input
 
START
from fiwo
hello difh
mars riwosf
earth fnnvk
like fiiwj
END
START
difh, i'm fiwo riwosf.
i fiiwj fnnvk!
END
 
Sample Output
 
hello, i'm from mars.
i like earth!
 
 

Huge input, scanf is recommended.

 
 
 
 /*
模板题 */
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
using namespace std; struct Tril
{
char a[];
struct Tril *next[];
};
Tril *root;
void mem(Tril *p)
{
int i;
for(i=;i<;i++) p->next[i]=NULL;
p->a[]='\0';
} void insert_Tril(char *s1,char *s2)
{
int i,k,ans;
struct Tril *p=root,*q;
k=strlen(s2);
for(i=;i<k;i++)
{
ans=s2[i]-'a';
if( p->next[ans]==NULL )
{
q=(struct Tril*)malloc(sizeof(struct Tril));
mem(q);
p->next[ans]=q;
p=q;
}
else
{
p=p->next[ans];
}
}
strcpy(p->a,s1);
}
void found_Tril(char *s1)
{
int i,k,ans;
struct Tril *p=root;
bool flag=false;
k=strlen(s1);
for(i=;i<k;i++)
{
ans=s1[i]-'a';
if(p->next[ans]==NULL)
{
flag=true;
break;
}
else p=p->next[ans];
}
if(flag==true || strlen(p->a)==)
printf("%s",s1);
else printf("%s",p->a);
}
int main()
{
int i,k;
char s1[],s2[];
root=(struct Tril*)malloc(sizeof(struct Tril));
mem(root);
scanf("%s",s1);
while(scanf("%s",s1))
{
if( strcmp(s1,"END")==)break;
scanf("%s",s2);
insert_Tril(s1,s2);
}
scanf("%s",s1);
getchar();
while(gets(s1))
{
if( strcmp(s1,"END")==)break;
i=;
while(s1[i]!='\0')
{
if( s1[i]>'z'||s1[i]<'a')
{
printf("%c",s1[i]);
i++;
}
else
{
k=;
while(s1[i]<='z'&&s1[i]>='a' &&s1[i]!='\0')
{
s2[k]=s1[i];
i++;
k++;
}
s2[k]='\0';
found_Tril(s2);
}
}
printf("\n");
}
return ;
}
 

hdu 1075 What Are You Talking About 字典树模板的更多相关文章

  1. 字典树模板题(统计难题 HDU - 1251)

    https://vjudge.net/problem/HDU-1251 标准的字典树模板题: 也注意一下输入方法: #include<iostream> #include<cstdi ...

  2. HDU - 1251 字典树模板题

    Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己的前缀).  Input输入数据的第一部 ...

  3. 字典树模板 HDU - 1251

    题意: 给一些单词,换行键后,查找以后输入的单词作为前缀的话们在之前出现过几次. 思路: 字典树模板----像查字典的顺序一样 #include<string> #include<s ...

  4. hdu1521(字典树模板)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1251 题意: 中文题诶~ 思路: 字典树模板 代码1: 动态内存, 比较好理解一点, 不过速度略慢, ...

  5. CH 1601 - 前缀统计 - [字典树模板题]

    题目链接:传送门 描述给定 $N$ 个字符串 $S_1,S_2,\cdots,S_N$,接下来进行 $M$ 次询问,每次询问给定一个字符串 $T$,求 $S_1 \sim S_N$ 中有多少个字符串是 ...

  6. HDU 4825 Xor Sum(经典01字典树+贪心)

    Xor Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others) Total ...

  7. HDU 2072 - 单词数 - [(有点小坑的)字典树模板题]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2072 Problem Descriptionlily的好朋友xiaoou333最近很空,他想了一件没有 ...

  8. HDU 1251 统计难题(字典树模板题)

    http://acm.hdu.edu.cn/showproblem.php?pid=1251 题意:给出一些单词,然后有多次询问,每次输出以该单词为前缀的单词的数量. 思路: 字典树入门题. #inc ...

  9. HDU:1251-统计难题(字典树模板,动态建树,静态建树)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1251 统计难题 Time Limit: 4000/2000 MS (Java/Others) Memor ...

随机推荐

  1. djngo 1.9版本以后 Foreignkey() 字段 第二个参数 on_delete 必不可少, mysql 外键可以为空

    一.外键的删除 1.常见的使用方式(设置为null) class BookModel(models.Model): """ 书籍表 """ ...

  2. django 模型 使用 DateTimeFields 字段 auto_now_add 属性 实现 插入数据时 自动记录时间

    class MyModel(models.Model): user_name = models.CharField() created = models.DatedTimeField(auto_now ...

  3. Java多线程原理及Thread类的使用

    一.进程与线程的区别 1.进程是应用程序在内存总分配的空间.(正在运行中的程序) 2.线程是进程中负责程序执行的执行单元.执行路径. 3.一个进程中至少有一个线程在负责进程的运行. 4.一个进程中有多 ...

  4. PUSH的整体设计

  5. sele nium 模块

    python3 web测试模块selenium   阅读目录 1.selenium安装配置 2.Selenium的基本使用 (1)声明浏览器对象 (2)定位元素 (3)元素对象(element) (4 ...

  6. JMeter 源码二次开发函数示例

    JMeter 源码二次开发函数示例 一.JMeter 5.0 版本 实际测试中,依靠jmeter自带的函数已经无法满足我们需求,这个时候就需要二次开发.本次导入的是jmeter 5.0的源码进行实际的 ...

  7. springmvc常遇到的错误

    错误1: HTTP Status 500 - Handler processing failed; nested exception is java.lang.NoClassDefFoundError ...

  8. day5:python学习之集合

    0. 集合的作用及特点 集合具有去重和关系测试两大作用,它具有无序的特点. list1 = [1,2,3,4,5,7,6,8,6,4] list1 = set(list1) print(list1) ...

  9. Vue 不睡觉教程3 - 来点实在的:自动计算剩余时间的任务列表

    目标前两课教的是入门和文件结构.都没有什么实在的东西.这次我们要来点实在的.我们要做出一个待办列表.这个待办列表有以下特点: 可以自动从文本中抽取出这件事情的开始时间可以显示当前距离这件事情的开始时间 ...

  10. 【HNOI2019】部分题简要题解

    题意懒得写了 LOJ Day 1 T1 鱼 个人做法比较猎奇,如果有哪位大佬会证明能分享一下的话感激不尽. 题解:枚举鱼尾和鱼身的交点D,将所有其他点按照到D的距离排序,距离相同的分一组. 感性的理解 ...