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. Q4m使用手册

    q4m是基于mysql存储引擎的轻量级消息队列,通过扩展SQL语法来操作消息队列,使用简单,容易上手,开发人员基本不用再进行学习和熟悉.Q4M支持多发送方,多接收方,接收方相互不影响,php项目中异步 ...

  2. excel冻结窗口

    Excel中如果输入内容太多,希望滚动时候,可以看到表头,需要冻结表格.如果我们选中C3表格,执行冻结操作,会看到C3左边和上边有两条直线,这样C3的左边和上边的表格都没法变动,因此冻结表格只能冻结首 ...

  3. [CSS3] 3D桃心

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  4. AI 的下一个重大挑战:理解语言的细微差别

    简评:人类语言非常博大精妙,同一句话在不同的语境下,就有不同的含义.连人类有时候都不能辨别其中细微的差别,机器能吗?这就是人工智能的下一个巨大挑战:理解语言的细微差别.本文原作者是 Salesforc ...

  5. Redis学习笔记(6)——SpringDataRedis入门

    一.SpringDataRedis简介 Spring-data-redis是spring大家族的一部分,提供了在srping应用中通过简单的配置访问redis服务,对reids底层开发包(Jedis, ...

  6. 对 ArrayList 进行分页.

    /** * 测试分页 */ @Test public void testPage() { int bulkSize = 2; List<Integer> dataList = new Ar ...

  7. [转] 如何在 CentOS7 中使用阿里云的yum源

    [From] https://www.cnblogs.com/lpbottle/p/7875400.html 1. 备份原来的yum源 mv /etc/yum.repos.d/CentOS-Base. ...

  8. WebGIS简单实现一个区域炫酷的3D立体地图效果

    1.别人的效果 作为一个GIS专业的,做一个高大上的GIS系统一直是我的梦想,虽然至今为止还没有做出一个理想中的系统,但是偶尔看看别人做的,学习下别人的技术还是很有必要的.眼睛是最容易误导我们的,有时 ...

  9. IT人生的价值和意义 感觉真的有了

     为了做新闻APP,我居然短短一个月利用业余时间做了: 一个通用新闻采集器. 一个新闻后台审核网站. 一个通用采集器下载网站. 一个新闻微网站. 一个新闻APP, 而且还给新闻微网站和新闻 APP练就 ...

  10. JavaScript设计模式(一)

    什么是设计模式呢? 就是指对于类似的问题,我们可以用大致相同的思想.方法去解决之,而这种通用的思想.方法就是设计模式.学习设计模式可以帮助我们在遇到问题时迅速地搜索出一种清晰的思路来实现之. 第一部分 ...