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

最新文章

  1. Android性能优化之App应用启动分析与优化
  2. Git 进阶指南
  3. 解决 android 高低版本 webView 里内容 自适应屏幕的终极方法
  4. 浅谈2D游戏设计模式3 - 冒险地图之美(1)
  5. 从零自学Hadoop(17):Hive数据导入导出,集群数据迁移下
  6. 关于 presentViewController 时机
  7. 20135316王剑桥 linux第十周课实验笔记
  8. 维护计划生成的SSIS包存储在哪
  9. n盏灯亮灭问题
  10. HDU1395+快速幂
  11. Python自动化运维之26、Web框架本质、MVC与MTV
  12. E6全部刷机包
  13. hdu 3221 Brute-force Algorithm(高速幂取模,矩阵高速幂求fib)
  14. Java内部类详解(转)
  15. 【JSOI2008】最大数
  16. instr函数的&quot;重载&quot;
  17. windows 7 wifi热点配置
  18. 201621123068 《Java程序设计》第1周学习总结
  19. 保护代理模式-Access Proxy(Java实现)
  20. Tensorflow serving with Kubernetes

热门文章

  1. mysql-安全管理
  2. WET Dilutes Performance Bottlenecks
  3. Zepto源代码分析之二~三个API
  4. jsp出现错误can not find the tag directory /web-inf/tags
  5. Java数组与栈内存、堆内存
  6. Kali linux 2016.2(Rolling)中metasploit的搜集特定网站的目录结构
  7. fixed说明
  8. PostgreSQL Replication之第三章 理解即时恢复(1)
  9. python 进阶:修饰器的介绍
  10. JDK工具(一)–Java编译器javac