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
of a foreign language. Fortunately, you have a dictionary to help you understand them.
我们人类的单词在老鼠的词典里面并不适用,所以我们必须来翻译这些词语。这里有许多组人类的单词在老鼠词典里面的写法是什么样的,之后我们有许多询问,对于每个询问求出每个询问在字典里面对应的单词是什么。
Input
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
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
#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)的更多相关文章
- 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 ...
- 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] ...
- SQLServer如何手动设置id值(主键)的自动增长
近期做东西,用到了对SQLServer数据库的操作.好吧,确实好久没看了,对这个数据库陌生到了极点,连最简单的如何设置一个id主键,让它随着插入数据的增多,自动增长id值的设置都忘记了,网上查了一下, ...
- 烟大 Contest1025 - 《挑战编程》第二章:数据结构 Problem A: Jolly Jumpers(水题)
Problem A: Jolly Jumpers Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 10 Solved: 4[Submit][Status] ...
- 烟大 Contest1024 - 《挑战编程》第一章:入门 Problem C: The Trip(水题)
Problem C: The Trip Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 19 Solved: 3[Submit][Status][Web ...
- 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, ...
- Codeforces 713C Sonya and Problem Wihtout a Legend(单调DP)
[题目链接] http://codeforces.com/problemset/problem/713/C [题目大意] 给出一个数列,请你经过调整使得其成为严格单调递增的数列,调整就是给某些位置加上 ...
- fzu Problem - 2232 炉石传说(二分匹配)
题目链接:http://acm.fzu.edu.cn/problem.php?pid=2232 Description GG学长虽然并不打炉石传说,但是由于题面需要他便学会了打炉石传说.但是传统的炉石 ...
- snowflake自增ID算法 (PHP版)
/** * SnowFlake ID Generator * Based on Twitter Snowflake to generate unique ID across multiple * da ...
随机推荐
- 编程实现prim算法和Dijkstra算法。
网址链接:http://blog.csdn.net/anialy/article/details/7603170
- jq的合成事件
jq中有两个合成事件 hover()和toggle() 1.hover() hover方法用于模拟光标悬停事件.当光标移动到元素上时,会触发指定的第一个函数(enter),当光标移出这个元素时,会触发 ...
- 阿里云资深DBA专家罗龙九:云数据库十大经典案例分析【转载】
阿里云资深DBA专家罗龙九:云数据库十大经典案例分析 2016-07-21 06:33 本文已获阿里云授权发布,转载具体要求见文末 摘要:本文根据阿里云资深DBA专家罗龙九在首届阿里巴巴在线峰会的&l ...
- CenOS 用PF_RING优化Snort
0.优化顺序 安装PF_RING的kernel模块 安装PF_RING的用户态库 安装Snort的DAQ 安装PF_RING的pfring-daq-module 安装snort 安装PF_RING-a ...
- (转)Hadoop MapReduce链式实践--ChainReducer
版本:CDH5.0.0,HDFS:2.3.0,Mapreduce:2.3.0,Yarn:2.3.0. 场景描述:求一组数据中按照不同类别的最大值,比如,如下的数据: data1: A,10 A,11 ...
- Mysql 中文乱码问题完美解决方案
MySQL会出现中文乱码的原因不外乎下列几点: 1.server本身设定问题,例如还停留在latin1 2.table的语系设定问题(包含character与collation) 3.客户端程式(例如 ...
- 【hihoCoder 第133周】2-SAT·hihoCoder音乐节
http://hihocoder.com/contest/hiho133/problem/1 2-sat模板...详细的题解请看题目里的提示. tarjan模板打错again致命伤qwq #inclu ...
- 解决adb command not found以及sdk环境配置
解决adb command not found以及sdk环境配置 分类: mark 2013-10-02 09:41 2975人阅读 评论(0) 收藏 举报 原文地址:http://www.cnblo ...
- MOS管常识
http://anlx27.iteye.com/blog/1583089 学过模拟电路,但都忘得差不多了.重新学习MOS管相关知识,大多数是整理得来并非原创.如有错误还请多多指点! 先上一张图 一. ...
- jQuery + json 实现省市区三级联动
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...