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. 关于python的可变和不可变对象

    在python中所有都是对象,在python中只有list和dict是可变对象,其他都是不可变对象. 具体参照:http://www.cnblogs.com/lovemo1314/archive/20 ...

  2. nodejs实践-代码组织

    nodejs实践-代码组织 laiqun@msn.cn Contents 1. 代码组织 1. 代码组织 更新版本 npm install -g n n latest 项目文件组织 MVC 前后端代码 ...

  3. 在web项目中使用cxf开发webservice,包含spring支持

    本文主要介绍了,如何使用cxf内置的例子,学会开发webserivce,在web项目中使用,且包含spring支持. webserivce的开发可以使用cxf或者axis,好像还有httpclient ...

  4. linux下libreoffice安装测试

    一.Linux安装 wget http://download.documentfoundation.org/libreoffice/stable/4.4.6/rpm/x86_64/LibreOffic ...

  5. java thread park

    http://agapple.iteye.com/blog/970055 apidoc中说,park/unpark用来阻塞/激活线程,但是没有弃用方法suspend/resume的缺点,suspend ...

  6. 1.2 selenium IDE录制脚本

    1.打开Firefox浏览器中 selenium IDE

  7. 【第k小素数 】 打表问题

    Prime Number TimeLimit: 1 Second MemoryLimit: 32 Megabyte Totalsubmit: 399 Accepted: 88 Description ...

  8. FZU 2030 括号问题(回溯)

    两种做法,一种dp,一种dfs,因为这个数据比较小,所以dfs全排列的方式是可以接受的,但是当比较大的时候就不行了,所以dp的方式还是要掌握一下的,我这里是dfs的做法,网上有很多人写的dp,可以去看 ...

  9. Python3基础 当函数中的局部变量与全局变量同名了,各管各的

    镇场诗: 诚听如来语,顿舍世间名与利.愿做地藏徒,广演是经阎浮提. 愿尽吾所学,成就一良心博客.愿诸后来人,重现智慧清净体.-------------------------------------- ...

  10. UML学习小结

    最近在使用状态模式写一个仿Windows计算器的MFC程序,顺便学习了一下UML图的绘制,尤其是类图和状态图的绘制,这里做一下总结吧.    一.UML简介 统一建模语言UML(Unified Mod ...