What Are You Talking About

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

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!
题意:一对字符串相互对应,
现在给你一串字符,让你翻译,可以选择map写 我用字典树写的  输入数据有点懵
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<cstdlib>
#include<string>
#define eps 0.000000001
typedef long long ll;
typedef unsigned long long LL;
using namespace std;
const int N=+;
struct tire{
char str[N];
int flag;
struct tire *next[];
};
tire *root;
tire *init(){
tire *p=(tire *)malloc(sizeof(tire));
for(int i=;i<;i++){
p->next[i]=NULL;
}
// p->terminal=false;
p->flag=;
return p;
}
void insert(char *a,char *b){
int i=;
tire *p=root;
while(b[i]!='\0'){
if(p->next[b[i]-'a']==){
p->next[b[i]-'a']=init();
}
p=p->next[b[i]-'a'];
//p->num++;
i++;
}
p->flag=;
strcpy(p->str,a);
}
void find(char *str){
int i=;
tire *p=root;
while(str[i]!='\0'&&p->next[str[i]-'a']){
p=p->next[str[i]-'a'];
i++;
}
if(str[i]=='\0'&&p->flag){
printf("%s",p->str);
}
else
printf("%s",str); }
int main()
{
char word[],trans[];
char s[];
scanf("%s",word);
root=init();
while(scanf("%s",word)!=EOF){ //输入字典
if(strcmp(word,"END")==) //遇到结束标记
break;
scanf("%s",s);
insert(word,s); //将单词word插入到字典树中,并在最后加入其翻译
}
scanf("%s",word);
getchar();
char str[];
while(gets(str)){
if(strcmp(str,"END")==)
break;
int i,j=;
char t[]={};
for(i=;str[i];i++){
if('a'<=str[i] && str[i]<='z'){ //检测到的是小写字母
t[j++] = str[i];
}
else{
t[j] = '\0';
if(t[]!='\0'){ //不是空的
find(t); //找到对应的翻译并输出,没找到则输出原来的字符串
t[]='\0',j=; //初始化t
}
printf("%c",str[i]);
}
}
printf("\n");
} return ;
}
/*
int main(){
char str1[N],str2[N],str3[N],str4[N],s[N];
gets(str1);
root=init();
while(scanf("%s",str2)!=EOF){
if(strcmp(str2,"END")==0)break;
scanf("%s",str3);
insert(str2,str3);
}
//getchar();
gets(str4);
getchar();
char a[N];
//getchar();
while(gets(s)){
//find(s);
int k=0;
if(strcmp(s,"END")==0)break;
int len=strlen(s);
int flag=0;
for(int i=0;i<len;i++){
if(s[i]>='a'&&s[i]<='z'){
a[k++]=s[i];
}
else{
a[k]='\0';
if(a[0]!='\0'){
find(a);
k=0;
a[0]='\0';
}
printf("%c",s[i]);
} }
cout<<endl;
}
}*/
Hint

Huge input, scanf is recommended.

hdu 1075(字典树)的更多相关文章

  1. hdu 1075 字典树

    #include<stdio.h> #include<iostream> struct node { int num,i; node *a[27]; char s[20];// ...

  2. HDU 5687 字典树插入查找删除

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=5687 2016百度之星资格赛C题,直接套用字典树,顺便巩固了一下自己对字典树的理解 #include< ...

  3. HDU 5384 字典树、AC自动机

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=5384 用字典树.AC自动机两种做法都可以做 #include<stdio.h> #includ ...

  4. hdu 2112(字典树+最短路)

    HDU Today Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  5. hdu 2072(字典树模板,set,map均可做)

    地址:http://acm.hdu.edu.cn/showproblem.php?pid=2072 lily的好朋友xiaoou333最近很空,他想了一件没有什么意义的事情,就是统计一篇文章里不同单词 ...

  6. Chip Factory HDU - 5536 字典树(删除节点|增加节点)

    题意: t组样例,对于每一组样例第一行输入一个n,下面在输入n个数 你需要从这n个数里面找出来三个数(设为x,y,z),找出来(x+y)^z(同样也可以(y+z)^1)的最大值 ("^&qu ...

  7. hdu 1251 字典树的应用

    这道题看了大神的模板,直接用字典树提交的会爆内存,用stl 里的map有简单有快 #include <iostream> #include <map> #include < ...

  8. hdu 2896 字典树解法

    #include <iostream> #include <cstring> #include <cstdio> #include <cstdlib> ...

  9. Repository HDU - 2846 字典树

    题意:给出很多很多很多很多个 单词 类似搜索引擎一下 输入一个单词 判断有一个字符串包含这个单词 思路:字典树变体,把每个单词的后缀都扔字典树里面,这里要注意dd是一个单词 但是把d 和dd都放字典树 ...

随机推荐

  1. Android基础TOP3_1:纵横屏切换

    在Res下建立layout-port文件夹  为竖屏时加载的界面: 建立layout-land 文件夹 为横屏加载的界面

  2. html5——全屏滚动

    鼠标滚轮 window.onmousewheel=function(){}; 基本描述 1.我们使用插件fullpage,为了更好的兼容性 2.动画效果是在滚动到这一屏时触发的,此时给当前屏幕加cur ...

  3. dubbo之连接控制

    连接控制 服务端连接控制 限制服务器端接受的连接不能超过 10 个 1: <dubbo:provider protocol="dubbo" accepts="10& ...

  4. Caffe2:段错误(核心 已转储)

    测试Caffe的时候, cd ~ && python -c 'from caffe2.python import core' 2>/dev/null && ech ...

  5. Python开发工具搭建-Pycharm

    PyCharm2017. 3.X专业版 安装使用. 注册码激活 本文以 Windows系统 为例: 1.开发工具获取及下载 Anaconda(Python 的集成工具 ) 下载地址: https:// ...

  6. 报错:command not found

    linux中如果是最小化安装的系统,执行命令的时候很多会出现没找到命令 [root@localhost ~]# mtr -bash: mtr: command not found [root@loca ...

  7. CF1148D-Dirty Deeds Done Dirt Cheap

    这轮CF怎么充满了替身啊233(这是场只有替身使者才能看见的比赛) 题解可以看官方的 这里就是记录下自己当初是怎么没做上的233 忽视掉了分类后pair本身就会带有的性质(a<b or a> ...

  8. php第十九节课

    JQUERY <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www. ...

  9. 计蒜客 劫富济贫 (Trie树)

    链接 : Here! 思路 : Trie树裸题, 由开始给出的名字建一棵字典树, 然后每次查询一下抢♂劫的人名是否在字典树中, 复杂度也不清楚是多少, 反正是没给出 $M$ 的范围, 开始时用 $ha ...

  10. 洛谷——P1196 [NOI2002]银河英雄传说

    P1196 [NOI2002]银河英雄传说 题目大意: 给你一个序列,支持两种操作: 合并指令为$M_{i,j}$j​,含义为第i号战舰所在的整个战舰队列,作为一个整体(头在前尾在后)接至第j号战舰所 ...