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. Linux中防火墙centos

    一般的防火墙用下面这些简单的配置都能达到目的 1) 重启后生效 开启: chkconfig iptables on 关闭: chkconfig iptables off 2) 即时生效,重启后失效 开 ...

  2. AJAX(XMLHttpRequest)进行跨域请求方法详解(一)

    注意:以下代码请在Firefox 3.5.Chrome 3.0.Safari 4之后的版本中进行测试.IE8的实现方法与其他浏览不同. 跨域请求,顾名思义,就是一个站点中的资源去访问另外一个不同域名站 ...

  3. Genymotion开启就全部白屏解决方法

    Genymotion开启就整个界面全部白屏,包括菜单栏也白屏,解决方法: 很可能是显卡驱动有问题,用驱动人生或者驱动精灵更新显卡驱动就可以了. 目前开发者好用的模拟器有: 1.Genymotion 2 ...

  4. Linux批量替换文本,文件夹内所有文本内容

    1.替换文件夹内所有文件匹配的字符串 sed -i "s/旧内容/新内容/g" `grep 旧内容 -rl 文件夹路径` 例如将/var/www/test文件夹下的所有文件内容中的 ...

  5. java集合框架工具类Collections,集合的操作

    1 import java.util.*; public class asList { public static void main(String args[]) { // int arr[] = ...

  6. ST Visual Programmer批量烧写教程

    源:ST Visual Programmer批量烧写教程 参考:为什么STM8 写了保护后,用ST Visual Programmer 无法重新烧录程序? 首先要说下为什么要建立烧写工程呢- -原因只 ...

  7. 关于Jsp页面在ww:iterator 标签里面判断的写法是可以直接写数组里面的变量的

    因为上面已经遍历了,所以可以直接写变量名

  8. 用CSS让文字居于div的底部

    css对文字的布局上没有靠容器底部对齐的参数,目前使用的一个不错的方法也比较好.就是用position属性来解决,看下面的代码,用position的相对和绝对定位功能也轻松的实现了,文字靠近div低部 ...

  9. PHP 删除非法UTF-8字符

    //reject overly long 2 byte sequences, as well as characters above U+10000 and replace with ? $some_ ...

  10. 在MAC下配置MySQL 5.7 数据库的编码问题

    1.MySQL 5.7 for MAC 默认没有my.cnf文件 ,首先 新建my.cnf文件: 2.在my.cnf文件追加 [mysqld] character-set-server=utf8mb4 ...