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项目实战_手机安全卫士软件管家

    ###1.应用程序信息的flags 1. int flags = packageInfo.applicationInfo.flags2. 0000 0000 0000 0000 0000 0000 0 ...

  2. PAT甲级1016Phone Bills

    #include<iostream> #include<cstdio> #include<cstdlib> #include<vector> #incl ...

  3. CDR如何使用钢笔工具进行完美抠图?【6·18特惠倒计时!】

    不要以为抠图只能在图像处理软件中实现,矢量图形绘制软件CorelDRAW一样可以,而且方法很多,文章介绍使用CDR钢笔工具抠图的方法. 提示说明: 首先说明一下,CDR中的钢笔工具和其他平面设计软件中 ...

  4. jquery from使用

    jquery form是一个基于jquery的表单异步提交的插件,通过它能快速简便的提交表单. html <div> <form id="ajaxForm" me ...

  5. S-HR之OSF

    1):getWorkDayCount ->ArrayList data = (ArrayList) com.kingdee.shr.rpts.ctrlreport.osf.OSFExecutor ...

  6. pandas.DataFrame.quantile

    pandas.DataFrame.quantile 用于返回数据中的 处于1/5    1/2(中位数)等数据

  7. Quartz.NET 定时任务使用

    class Program { static void Main(string[] args) { StartJob(); Console.ReadKey(); } static void Start ...

  8. 洛谷——P1757 通天之分组背包

    P1757 通天之分组背包 题目背景 直达通天路·小A历险记第二篇 题目描述 自01背包问世之后,小A对此深感兴趣.一天,小A去远游,却发现他的背包不同于01背包,他的物品大致可分为k组,每组中的物品 ...

  9. python数字取反~

    >>> a = [1,2,3,4,5,7,6,4,2,10] >>> h = len(a)//2 >>> h 5 >>> ~h ...

  10. Centos6防火墙基本配置

    1. 允许x.x.x.x访问本机 iptables -I INPUT -p tcp -j DROP #若要添加多了ip,该条也是只执行一次 iptables -I INPUT -s x.x.x.x - ...