HDU——T 1075 What Are You Talking About
2024-08-27 23:12:32
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
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!
i like earth!
Hint
Huge input, scanf is recommended.
Author
Ignatius.L
Recommend
题目处理很恶心、、
#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
最新文章
- Android性能优化之App应用启动分析与优化
- Git 进阶指南
- 解决 android 高低版本 webView 里内容 自适应屏幕的终极方法
- 浅谈2D游戏设计模式3 - 冒险地图之美(1)
- 从零自学Hadoop(17):Hive数据导入导出,集群数据迁移下
- 关于 presentViewController 时机
- 20135316王剑桥 linux第十周课实验笔记
- 维护计划生成的SSIS包存储在哪
- n盏灯亮灭问题
- HDU1395+快速幂
- Python自动化运维之26、Web框架本质、MVC与MTV
- E6全部刷机包
- hdu 3221 Brute-force Algorithm(高速幂取模,矩阵高速幂求fib)
- Java内部类详解(转)
- 【JSOI2008】最大数
- instr函数的";重载";
- windows 7 wifi热点配置
- 201621123068 《Java程序设计》第1周学习总结
- 保护代理模式-Access Proxy(Java实现)
- Tensorflow serving with Kubernetes