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. BZOJ2961: 共点圆(CDQ分治+凸包)

    题面 传送门 题解 这题解法真是多啊--据说可以圆反演转化为动态插入半平面并判断给定点是否在半平面交中,或者化一下改成给定点判断是否所有点都在某一个半平面内-- 鉴于圆反演我也不会,这里讲一下直接推的 ...

  2. hadoop1.0.4运行程序出现“Java heap Space”错误

    根据虾皮博客中教程,成功搭建了一个12台电脑的Hadoop云平台,而且成功运行了软件自带的wordcount程序,处理10M数据. 但是当程序处理40M时候,却出错了.出错提示“Java Heap S ...

  3. linux中创建一个回收站

      1. mkdir /tmp/trash_tmp 建立一个回收站目录 2. vi /bin/trash 编辑一个文件     mv $@ /tmp/trash_tmp     :wq 保存退出 3. ...

  4. python-------打印与字符串格式化

    print python中每次执行print时都会在新的一行上开始.形如:print(’xiao') print('ming') 结果为:>>>xiao >>>mi ...

  5. P1273 有线电视网(树形dp)

    P1273 有线电视网 题目描述 某收费有线电视网计划转播一场重要的足球比赛.他们的转播网和用户终端构成一棵树状结构,这棵树的根结点位于足球比赛的现场,树叶为各个用户终端,其他中转站为该树的内部节点. ...

  6. docker微服务部署之:五、利用DockerMaven插件自动构建镜像

    docker微服务部署之:四.安装docker.docker中安装mysql和jdk1.8.手动构建镜像.部署项目 在上一篇文章中,我们是手动构建镜像,即: 4.1.2.5.1.2.6.1.2中的将d ...

  7. java 实现七大基本排序算法

    一. 选择排序 /** * 选择排序: int arr[] = { 5, 6, 2, 7, 8, 6, 4 }; * * 第0趟 5 2 6 7 6 4 8 第1趟 2 5 6 6 4 7 8 第2趟 ...

  8. FTP在docker容器中上传失败解决,改为被动模式

    package com.mayocase.takeout.utils; import org.apache.commons.net.ftp.FTPClient; import org.apache.c ...

  9. C++类的构造函数及定义

    定义一个普通的类时,一定要定义它自己的构造函数.原因有三:第一个原因是编译器只有在发现类不包含任何构造函数的情况下才会替我们生成一个默认的构造函数,一旦我们定义了一些其他的构造函数,那么除非我们再定义 ...

  10. 在linux上安装 sql server for linux

    在linux上安装 sql server for linux Install SQL Server on Red Hat Enterprise Linux Install SQL Server To ...