http://begin.lydsy.com/JudgeOnline/problem.php?id=2770(PKU2503 Babelfish)

2770: PKU2503 Babelfish

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 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.
我们人类的单词在老鼠的词典里面并不适用,所以我们必须来翻译这些词语。这里有许多组人类的单词在老鼠词典里面的写法是什么样的,之后我们有许多询问,对于每个询问求出每个询问在字典里面对应的单词是什么。

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.

Output

Output is the message translated to English, one word per line. Foreign words not
in the dictionary should be translated as "eh".

Sample Input

dog ogday
cat atcay
pig igpay
froot ootfray
loops oopslay

atcay
ittenkay
oopslay

Sample Output

cat
eh
loops

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 }

时间: 2024-10-09 12:34:53

http://begin.lydsy.com/JudgeOnline/problem.php?id=2770(PKU2503 Babelfish)的相关文章

Zju1290 Word-Search Wonder(http://begin.lydsy.com/JudgeOnline/problem.php?id=2768)

2768: Zju1290 Word-Search Wonder Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 4  Solved: 2[Submit][Status][Web Board] Description The Pyrates Restaurant was starting to fill up as Valentine McKee walked in. She scanned the crowd for her sister, bro

SQLServer如何手动设置id值(主键)的自动增长

近期做东西,用到了对SQLServer数据库的操作.好吧,确实好久没看了,对这个数据库陌生到了极点,连最简单的如何设置一个id主键,让它随着插入数据的增多,自动增长id值的设置都忘记了,网上查了一下,好多人都说使用代码,好像跟我要的不一样,然后在百度知道找到了答案,虽然有点不好意思,但还是贴出来吧: 问:如何手动设置SQLServer的id(主键),让它随着插入的数据自动增长? 答:点击需要设置的表,点击右键——设计——在列中,点击id——下方出现如下的图: 自增定义: 然后点击确定即可!!!!

河工大校赛 魔法宝石 http://218.28.220.249:50015/JudgeOnline/problem.php?id=1262

题目就是一道最短路的变形  数据比较大  所以使用邻接表以及队列来完成 #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<queue> #include<vector> #include<map> #include<math.h> using namespace std; #define INF

河工大校赛 Hmz 的女装 http://218.28.220.249:50015/JudgeOnline/problem.php?id=1265

一个数学公式  当然单纯的推   是很难推出来的 题意所计算的没有现成的公式  但是能够通过转化找到我们所要的 所需要的公式  :用m个颜色去涂n个区域 要求相邻不同色 公式: (m-1)的n次方+(m-1)*(-1)的n次方 而我们需要的是两个点必须相同   所以可以规划成两个只有一个相交点的多边形 比如n=8要1和4的相同  就可以理解为123三点组成一个环  而45678五个点组成一个环 我们将两个环的种数相乘  因为1和4颜色相同  所以要再除以k  也就是多出了一个k 所以又用到  (

FZU Problem 2102 Solve equation (数学啊 )

题目链接:http://acm.fzu.edu.cn/problem.php?pid=2102 Problem Description You are given two positive integers A and B in Base C. For the equation: A=k*B+d We know there always existing many non-negative pairs (k, d) that satisfy the equation above. Now in

FZU Problem 2111 Min Number (数学啊 )

题目链接:http://acm.fzu.edu.cn/problem.php?pid=2111 Problem Description Now you are given one non-negative integer n in 10-base notation, it will only contain digits ('0'-'9'). You are allowed to choose 2 integers i and j, such that: i!=j, 1≤i<j≤|n|, her

Codeforces 713C Sonya and Problem Wihtout a Legend(单调DP)

[题目链接] http://codeforces.com/problemset/problem/713/C [题目大意] 给出一个数列,请你经过调整使得其成为严格单调递增的数列,调整就是给某些位置加上或者减去某个数,调整的代价是加上或者减去的数的绝对值之和,请你输出最小代价. [题解] 先考虑这样一个问题,如果是非严格单调递增该如何做,我们会发现每次调整,都是调整某个数字为原先数列中存在的数字,最后才是最优的,所以,我们设DP[i][j]表示前i个数字,最后一个数为原先数列排序后第j大的数字的最

FZU Problem 2151 OOXX Game (数学啊)

题目链接:http://acm.fzu.edu.cn/problem.php?pid=2151 Problem Description Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows, M columns). At the beginning, there are N*M coins in this board with two symbol "O" or

UVA - 146 - ID Codes (枚举排列)

UVA - 146 ID Codes Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description It is 2084 and the year of Big Brother has finally arrived, albeit a century late. In order to exercise greater control over its ci