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

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

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
We have carefully selected several similar problems for you:  1800 1671 1247 1298 1026 
 
 
题目处理很恶心、、
 #include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <cctype>
#include <cstdio>
#include <map> using namespace std; map<string,string>mmp;
char s[];
string a,b; int main()
{
cin>>a;
for(;cin>>a&&a!="END";)
cin>>b,mmp[b]=a;
cin>>a;
getchar();
for(int len;gets(s)&&strcmp(s,"END");)
{
len=strlen(s); a="";
for(int i=;i<len;i++)
if(islower(s[i])) a+=s[i];
else
{
if(mmp.find(a)!=mmp.end())
cout<<mmp[a];
else cout<<a;
a=""; cout<<s[i];
}
cout<<endl;
}
return ;
}

MAP——AC

 #include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <cctype>
#include <cstdio> using namespace std; string a,b,ans;
char s[];
struct Trie
{
int next[];
string ans;
}tr[];
int tot; inline void Trie_build()
{
int now=,len=b.length();
for(int i=;i<len;i++)
{
int x=b[i]-'a';
if(tr[now].next[x])
now=tr[now].next[x];
else tr[now].next[x]=++tot,now=tot;
}
tr[now].ans+=a;
}
inline bool Trie_find()
{
int now=,p=;
int len=a.length();
for(;p<len;p++)
if(tr[now].next[a[p]-'a'])
now=tr[now].next[a[p]-'a'];
else return ;
ans=tr[now].ans;
if(!ans.length()) return ;
return ;
} int main()
{
cin>>a;
for(;cin>>a&&a!="END";)
cin>>b,Trie_build();
cin>>a;
getchar();
for(int len;gets(s)&&strcmp(s,"END");)
{
len=strlen(s); a="";
for(int i=;i<len;i++)
if(islower(s[i])) a+=s[i];
else
{
if(Trie_find()) cout<<ans;
else cout<<a; ans="";a="";
cout<<s[i];
}
memset(s,,sizeof(s));
cout<<endl;
}
return ;
}

Trie树——AC

HDU——T 1075 What Are You Talking About的更多相关文章

  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 (map)

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

  3. hdu 1075 What Are You Talking About

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

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

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

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

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

  6. 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 ...

  7. hdu 1075:What Are You Talking About(字典树,经典题,字典翻译)

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

  8. hdu 1075 二分搜索

    还是写一下,二分搜索好了 这道题开数组比较坑... 二分,需要注意边界问题,例如:左闭右闭,左闭右开,否则查找不到or死循环 先上AC代码 #include<iostream> #incl ...

  9. HDOJ/HDU 1075 What Are You Talking About(字符串查找翻译~Map)

    Problem Description Ignatius is so lucky that he met a Martian yesterday. But he didn't know the lan ...

随机推荐

  1. .NET 框架简单介绍

    初学.NET肯定会有一系列的疑问,比方(下面为自己的疑问): 1) 何为. NET框架.它都包括哪些东西? 2) 程序集是什么.它是怎样在CLR(通用语言执行时)中执行的? 3) C#与VB.NET同 ...

  2. HDU 5399 Too Simple (2015年多校比赛第9场)

    1.题目描写叙述:点击打开链接 2.解题思路:本题分情况讨论.比赛时候真是想的太简单了.以为就是(n!)^(cnt-1). 终于无限WA. 本题有几个特殊情况须要额外推断. 首先,假设输入的时候.有某 ...

  3. jsp布局中关于&lt;iframe&gt;标签的使用

    iframe 元素会创建包括另外一个文档的内联框架(即行内框架). 注意:在 HTML 4.1 Strict DTD 和 XHTML 1.0 Strict DTD 中,不支持 iframe 元素. & ...

  4. Redis的好处知识

    参考文章 http://www.cnblogs.com/wupeiqi/articles/5132791.html 使用Redis有哪些好处? () 速度快,因为数据存在内存中,类似于HashMap, ...

  5. python 字符串匹配问题

    想匹配html = <div class="back fl"><a href="javascript:void(0);" onclick=&q ...

  6. PostgreSQL Replication之第五章 设置同步复制(2)

    5.2 理解实际影响和性能 在本章中,我们已经讨论了实际影响以及性能影响.但是,有什么好的理论性的例子吗?让我们做一个简单的基准测试,看看复制是怎么做的.我们做这样的测试来为您显示各种耐久性的级别不只 ...

  7. 51Nod 1007 正整数分组(01背包)

    将一堆正整数分为2组,要求2组的和相差最小. 例如:1 2 3 4 5,将1 2 4分为1组,3 5分为1组,两组和相差1,是所有方案中相差最少的. Input 第1行:一个数N,N为正整数的数量. ...

  8. nginx的gizp压缩

    好处:         页面另存为大小比浏览器传输大小大很多.好处是加快传输.节省带宽.   原理:           浏览器 -> 请求 -> 声明可以接受的压缩方式[http 协议请 ...

  9. C#中使用Dictionary实现Map数据结构——VC编程网

    转载自: http://blog.51cto.com/psnx168 在VC中使用过CMap以及在Java中使用过Map的朋友应该很熟悉,使用Map可以方便实现基于键值对数据的处理,在C#中,你就需要 ...

  10. GIL解释锁及进程池和线程池

    官方介绍 ''' 定义: In CPython, the global interpreter lock, or GIL, is a mutex that prevents multiple nati ...