http://begin.lydsy.com/JudgeOnline/problem.php?id=2770(PKU2503 Babelfish)
来源:互联网 发布:拟线性偏好知乎 编辑:程序博客网 时间:2024/05/01 15:23
2770: PKU2503 Babelfish
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 2 Solved: 2
[Submit][Status][Web Board]
Description
You have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect
of a foreign language. Fortunately, you have a dictionary to help you understand them.
我们人类的单词在老鼠的词典里面并不适用,所以我们必须来翻译这些词语。这里有许多组人类的单词在老鼠词典里面的写法是什么样的,之后我们有许多询问,对于每个询问求出每个询问在字典里面对应的单词是什么。
of a foreign language. Fortunately, you have a dictionary to help you understand them.
我们人类的单词在老鼠的词典里面并不适用,所以我们必须来翻译这些词语。这里有许多组人类的单词在老鼠词典里面的写法是什么样的,之后我们有许多询问,对于每个询问求出每个询问在字典里面对应的单词是什么。
Input
Input consists of up to 100,000 dictionary entries, followed by a blank line, followed by
a message of up to 100,000 words. Each dictionary entry is a line containing an English word
followed by a space and a foreign language word. No foreign word appears more than once in the dictionary.
The message is a sequence of words in the foreign language, one word on each line. Each word in the input
is a sequence of at most 10 lowercase letters.
a message of up to 100,000 words. Each dictionary entry is a line containing an English word
followed by a space and a foreign language word. No foreign word appears more than once in the dictionary.
The message is a sequence of words in the foreign language, one word on each line. Each word in the input
is a sequence of at most 10 lowercase letters.
Output
Output is the message translated to English, one word per line. Foreign words not
in the dictionary should be translated as "eh".
in the dictionary should be translated as "eh".
Sample Input
dog ogdaycat atcaypig igpayfroot ootfrayloops oopslayatcayittenkayoopslay
Sample Output
catehloops
HINT
Source
题解:
这个看一眼就知道是trie树,随便乱搞搞就可以了。。。。。。
1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 //#include<string> 5 #define maxn 10000 6 using namespace std; 7 int sum[350000]; 8 int son[350000][26]; 9 char s1[100005][12],s2[100005][12];10 char s[100005];11 int tot,i,j;12 void insert(char *s,int num)13 {14 int p=0;15 for (int i=0; s[i]; p=son[p][s[i]-'a'],i++)16 if (!son[p][s[i]-'a']) son[p][s[i]-'a']=++tot;17 sum[p]=num;18 }19 int answer(char *s)20 {21 int p=0;22 for (int i=0; s[i]; p=son[p][s[i]-'a'],i++)23 if (!son[p][s[i]-'a'] ) return 0;24 return sum[p];25 } 26 int main()27 {28 int i=1;29 while (true) 30 {31 gets(s);32 if (s[0]=='\0') break;33 sscanf(s,"%s %s",s1[i],s2[i]);34 insert(s2[i],i);35 i++;36 }37 while (scanf("%s",s)!=-1)38 {39 i=answer(s);40 if (i==0) cout<<"eh"<<endl; else cout<<s1[i]<<endl;41 }42 }
0 0
- http://begin.lydsy.com/JudgeOnline/problem.php?id=2770(PKU2503 Babelfish)
- http://begin.lydsy.com/JudgeOnline/problem.php?id=2774(poi病毒)
- Zju1290 Word-Search Wonder(http://begin.lydsy.com/JudgeOnline/problem.php?id=2768)
- http://211.67.33.62/JudgeOnline/problem.php?id=1014,排序二叉树
- http://acm.pku.edu.cn/JudgeOnline/problem?id=1284 (原根)
- http://acm.nyist.net/JudgeOnline/problem.php?pid=290
- http://acm.nyist.net/JudgeOnline/problem.php?pid=434
- http://acm.nyist.net/JudgeOnline/problem.php?pid=13
- http://acm.nyist.net/JudgeOnline/problem.php?pid=239
- http://acm.nyist.net/JudgeOnline/problem.php?pid=129
- http://acm.nyist.net/JudgeOnline/problem.php?pid=431
- http://acm.nyist.net/JudgeOnline/problem.php?pid=301
- http://acm.nyist.net/JudgeOnline/problem.php?pid=451
- http://acm.nyist.net/JudgeOnline/problem.php?pid=459
- http://acm.nyist.net/JudgeOnline/problem.php?pid=20
- http://acm.nyist.net/JudgeOnline/problem.php?pid=267
- http://acm.nyist.net/JudgeOnline/problem.php?pid=305
- http://acm.nyist.net/JudgeOnline/problem.php?pid=309
- 关键词匹配(Ac自动机模板题)
- BufferKnife及插件使用
- 利用 ajax 像后台传递数组
- Android 优秀文章收集整理集合
- 5个最佳的Android测试框架(带示例)
- http://begin.lydsy.com/JudgeOnline/problem.php?id=2770(PKU2503 Babelfish)
- 10天精通Sass 之 Sass运算
- jsp内置对象之request
- http://begin.lydsy.com/JudgeOnline/problem.php?id=2774(poi病毒)
- [HNOI2004]Language L语言
- [Usaco2008 Dec]Secret Message 秘密信息
- [TJOI2013]单词
- [NOI2011]阿狸的打字机(好题!!!!)
- 【UVa】10200 - Prime Time(打表)