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树,随便乱搞搞就可以了。。。。。。
 #include<iostream>
#include<cstring>
#include<cstdio>
//#include<string>
#define maxn 10000
using namespace std;
int sum[];
int son[][];
char s1[][],s2[][];
char s[];
int tot,i,j;
void insert(char *s,int num)
{
int p=;
for (int i=; s[i]; p=son[p][s[i]-'a'],i++)
if (!son[p][s[i]-'a']) son[p][s[i]-'a']=++tot;
sum[p]=num;
}
int answer(char *s)
{
int p=;
for (int i=; s[i]; p=son[p][s[i]-'a'],i++)
if (!son[p][s[i]-'a'] ) return ;
return sum[p];
}
int main()
{
int i=;
while (true)
{
gets(s);
if (s[]=='\0') break;
sscanf(s,"%s %s",s1[i],s2[i]);
insert(s2[i],i);
i++;
}
while (scanf("%s",s)!=-)
{
i=answer(s);
if (i==) cout<<"eh"<<endl; else cout<<s1[i]<<endl;
}
}

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

  1. http://begin.lydsy.com/JudgeOnline/problem.php?id=2774(poi病毒)

    2774: Poi2000 病毒 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 5  Solved: 4[Submit][Status][Web Boa ...

  2. 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] ...

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

    近期做东西,用到了对SQLServer数据库的操作.好吧,确实好久没看了,对这个数据库陌生到了极点,连最简单的如何设置一个id主键,让它随着插入数据的增多,自动增长id值的设置都忘记了,网上查了一下, ...

  4. 烟大 Contest1025 - 《挑战编程》第二章:数据结构 Problem A: Jolly Jumpers(水题)

    Problem A: Jolly Jumpers Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 10  Solved: 4[Submit][Status] ...

  5. 烟大 Contest1024 - 《挑战编程》第一章:入门 Problem C: The Trip(水题)

    Problem C: The Trip Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 19  Solved: 3[Submit][Status][Web ...

  6. UVA 11991 Easy Problem from Rujia Liu?(vector map)

    Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for example, ...

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

    [题目链接] http://codeforces.com/problemset/problem/713/C [题目大意] 给出一个数列,请你经过调整使得其成为严格单调递增的数列,调整就是给某些位置加上 ...

  8. fzu Problem - 2232 炉石传说(二分匹配)

    题目链接:http://acm.fzu.edu.cn/problem.php?pid=2232 Description GG学长虽然并不打炉石传说,但是由于题面需要他便学会了打炉石传说.但是传统的炉石 ...

  9. snowflake自增ID算法 (PHP版)

    /** * SnowFlake ID Generator * Based on Twitter Snowflake to generate unique ID across multiple * da ...

随机推荐

  1. 使用nginx简单实现负载均衡

    只是简单使用nginx玩玩而已,知道能这么用,但是在实际项目中并没有实践过,在项目不大的时候用不到,但是对于理解负载均衡来说还是可以的. 利用虚拟机安装了三个centOS系统,然后顺便装了环境. 这里 ...

  2. Android Studio中有没有类似于Eclipse中的ctrl+2+L的快捷键? \Android Studio快捷键之代码提示

    问:Android Studio中有没有类似于Eclipse中的ctrl+2+L的快捷键? 答:有,as中的快捷键是Ctrl+Alt+V AndroidStudio和Eclipse常用快捷键对比 功能 ...

  3. xmppserver

    http://highscalability.com/blog/2014/1/6/how-hipchat-stores-and-indexes-billions-of-messages-using-e ...

  4. Envelope几何对象 Curve对象几何对象 Multipatch几何对象 Geometry集合接口 IGeometryCollection接口

    Envelope是所有几何对象的外接矩形,用于表示几何对象的最小边框,所有的几何对象都有一个Envelope对象,IEnvelope是Envelope对象的主要接口,通过它可以获取几何对象的XMax, ...

  5. Go语言实现列出排列组合

    今天,隔壁坐的小朋友给我一串数字: 1 6 21 55 让我观察规律,然后帮他推导公式. 尼玛,当我是神呢?!! 想了半天没看出个原委, 于是看了他那边具体需要才发现他那边是对N个数字进行5个数字的组 ...

  6. PAT (Advanced Level) 1058. A+B in Hogwarts (20)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  7. Android USER 版本与ENG 版本的差异--MTK官方解释

     分类: Android(4)  Description]Android USER 版本与ENG 版本的差异 [Keyword]USER ENG user eng 用户版本 工程版本 差异 [Solu ...

  8. eclipse shortcut binding

    有些真的是太方便了,我竟然不知道,比如ctrl + h 就是打开search 功能,包括file search,我竟然每次都点击工具条上的放大镜图标! use Ctrl+Shift+T for ope ...

  9. 猪八戒吃西瓜(wmelon)

    猪八戒吃西瓜(wmelon) 题目描述 有一天,贪吃的猪八戒来到了一个大果园,果园里有n(n≤100000)个大西瓜,每个西瓜 的质量不大于长整型(longint),并且每个西瓜的质量都不同.猪八戒非 ...

  10. iframe载入等待

    <style> #pageloading{position:absolute; left:0px; top:0px;background:white url('../images/load ...