What Are You Talking About

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

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!

Hint

Huge input, scanf is recommended.

 
Author
Ignatius.L
 
Recommend
 
 
就是给定一个火星的文字,然后对应着有地球的翻译,然后给定一段包含有火星文和地球文的文字,要你翻译成为地球文(如果是地球文,这直接输出,反之则翻译成为地球文。)
思路:  其实只需要将火星文做成一颗字典树(而且在每一个单词的末尾,填上一个tail,使其能够进行对应的查找。),然后对于每一个单词进行一次查找,如果有,则直接翻译,如果没有则直接输出。
 
代码:
 /*hdu 1075 字典树写法*/
//#define LOCAL
#include<cstdio>
#include<cstring>
#include<cstdlib>
typedef struct node
{
int id;
struct node *child[];
}Trie;
void Insert(char *s,Trie *root,int v)
{
Trie *cur=root,*curnew;
int i,pos;
for(i=;s[i]!='\0';i++){
pos=s[i]-'a';
if(cur->child[pos]==NULL)
{
curnew= new Trie;
curnew->id=;
for(int j=;j<;j++)
curnew->child[j]=NULL;
cur->child[pos]=curnew;
}
cur=cur->child[pos];
}
cur->id=v;
}
int query(char *s,Trie *root)
{
Trie *cur=root;
int i,pos;
for(i=;s[i]!='\0';i++){
pos=s[i]-'a';
if(cur->child[pos]!=NULL)
cur=cur->child[pos];
else return ; //输出原字符串
}
return cur->id;
}
char aa[][],bb[];
char str[];
int main()
{
#ifdef LOCAL
freopen("test.in","r",stdin);
#endif
Trie *root= new Trie ;
root->id=;
int st;
for(int i=;i<;i++)
root->child[i]=NULL;
scanf("%s",aa[]);
int i=;
while(scanf("%s",aa[i]),strcmp(aa[i],"END"))
{
scanf("%s",bb);
Insert(bb,root,i); //对应标号
i++;
}
scanf("%s",aa[]);
getchar();
while(gets(str),strcmp(str,"END"))
{
for(st=i=;str[i]!='\0';i++)
{
if(str[i]<'a'||str[i]>'z'){
if(i>st){
strncpy(aa[],str+st,i-st);
aa[][i-st]='\0';
printf("%s",aa[query(aa[],root)]);
}
st=i+;
printf("%c",str[i]);
}
}
puts("");
}
return ;
}

当然可以用map,在这里就不在补充啦!喵喵!O(∩_∩)O哈哈~

hdu----(1075)What Are You Talking About(trie之查找)的更多相关文章

  1. HDU 1075 What Are You Talking About(Trie的应用)

    What Are You Talking About Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/204800 K ...

  2. HDU 1075 What Are You Talking About (Trie)

    What Are You Talking About Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/204800 K ...

  3. 题解报告:hdu 1075 What Are You Talking About

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1075 Problem Description Ignatius is so lucky that he ...

  4. hdu 1075 (map)

    http://acm.hdu.edu.cn/showproblem.php?pid=1075 What Are You Talking About Time Limit: 10000/5000 MS ...

  5. hdu 1075 What Are You Talking About

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1075 题意:比较简单,易懂,这里不做说明. 解法:第一种方法:用map映射,耗时1000+ms:第二种 ...

  6. HDU 1057 What Are You Talking About trie树 简单

    http://acm.hdu.edu.cn/showproblem.php?pid=1075 题意 : 给一个单词表然后给一些单词,要求翻译单词表中有的单词,没有则直接输出原单词. 翻译文段部分get ...

  7. 字典树 HDU 1075 What Are You Talking About

    http://acm.hdu.edu.cn/showproblem.php?pid=1075 ;}

  8. HDU 1075-What Are You Talking About(Trie)

    题意: 给你一个字典 一个英文单词对应一个火星单词 给你一段火星文翻译成英文 字典上的没有的不翻译 分析: 没有给数据规模 字典树用链表 #include <map> #include & ...

  9. HDU 11488 Hyper Prefix Sets (字符串-Trie树)

    H Hyper Prefix Sets Prefix goodness of a set string is length of longest common prefix*number of str ...

随机推荐

  1. Cheatsheet: 2013 07.01 ~ 07.08

    .NET The overhead of async/await in NET 4.5 await Task, Task.Wait and Friends 350 Interview Question ...

  2. 【转载】ADO,OLEDB,ODBC,DAO的区别

    原文:ADO,OLEDB,ODBC,DAO的区别 ODBC(Open Database Connectivity,开放数据库互连) 1992年,微软公司开放服务结构(WOSA,Windows Open ...

  3. Phonegap项目中禁用WebViewBounce

    UIWebView是iOS SDK中一个最常用的控件,在PhoneGap中,默认也是使用UIWebView作为默认视图显示我们的HTML应用的.   在使用PhoneGap的项目中,默认WebView ...

  4. CUBRID学习笔记 3 net连接数据库并使用cubrid教程示例

    接上文 数据库安装好后,也可以测试语句了. 下面我们用c#写一个控制台程序,连接数据库,并读取数据. 一 下载驱动  net版的下 CUBRID ADO.NET Data Provider 9.3.0 ...

  5. codevs 1294 全排列 next_permuntation

    #include<bits/stdc++.h> using namespace std; #define ll long long #define pi (4*atan(1.0)) #de ...

  6. 移动端图表插件jChart.js的修改

    bug1: 折线图,设置datasetGesture : true时,Y轴的刻度值居然会变.会变也就算了,居然没地方设置不能变. bug2: 折线图,设置tap.point事件,和datasetGes ...

  7. Oracle中synonym和index

    笔记: Oracle-同义词--通过用户名(模式名).表名       --授权:grant create synonym to test1(system用户下授权))     --私有  creat ...

  8. 动态CSS--less

    忙了很久终于有时间来写点东西了,不知道大家有没有发现,我们在写CSS的时候总是在重复很多代码,一个相同的属性值往往要重复N次,以前我就经常想有没有什么办法能让我们不用一直重复的font-size啊co ...

  9. iOS - Swift Range 范围

    前言 Range:结构体,这个结构体用来表示一个区间的范围. public struct Range<Element : ForwardIndexType> : Equatable, Co ...

  10. iOS - TouchID 指纹识别

    前言 NS_CLASS_AVAILABLE(10_10, 8_0) @interface LAContext : NSObject 指纹识别功能是 iPhone 5s 推出的,SDK 是 iOS 8. ...