Babelfish
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 36967   Accepted: 15749

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

Huge input and output,scanf and printf are recommended.

Source

//16096K 2625MS
#include<iostream>
#include<cstdio>
#include<map>
#include<cstring> using namespace std; int main()
{
char s[100],s1[11];
string ss;
char c;
map<string,string>Q;
int num;
while(gets(s)&&s[0]!='\0') //读串比读多个字符快
{
int len=strlen(s);
int i;
for( i=0;i<len;i++)
{
if(s[i]==' ')
{s[i]='\0';
break;
}
}
ss=s+i+1;
Q[ss]=s;
}
while(~scanf("%s",s1))
{
if(Q[s1].size())
cout<<Q[s1]<<endl;
else
printf("eh\n");
}
}
// while(~scanf("%c",&c)) // 超时
// {
// if(c=='\n')
// break;
// num=0;
// while(c!=' ')
// {
// s[num++]=c;
// scanf("%c",&c);
// }
// s[num]='\0'; //够成字符串
// num=0;
// scanf("%c",&c); //防止上一个空格被读入
//
// while(c!='\n')
// {
// ss[num++]=c;
// scanf("%c",&c);
// }
// ss[num]='\0';
// Q[ss]=s;
// }

//字典树 26240K    <span id="transmark"></span>735MS
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib> using namespace std; char ss[100],s[100],c[100010][100];
int num=0;
struct node
{
int flag;
node *next[26];
}*head;
node * Creat()
{
node *p;
p=new node;
p->flag=0;
for(int i=0;i<26;i++)
p->next[i]=NULL;
return p;
}
int Build_Tree()
{
node *p=head;
int len=strlen(s);
for(int i=0;i<len;i++)
{
int a=s[i]-'a';
if(!p->next[a])
{
p->next[a]=Creat();
//p->next[a]->flag=num;
}
p=p->next[a];
}
p->flag=num;
}
int Find(char s1[])
{
int len=strlen(s1);
node *p=head;
for(int i=0;i<len;i++)
{
int a=s1[i]-'a';
if(!p->next[a])
{
return 0;
}
p=p->next[a];
}
return p->flag;
}
int main()
{
num=1;
head=Creat();
while(gets(ss)&&ss[0]!='\0')
{
sscanf(ss,"%s %s",c[num],s);
Build_Tree();
num++;
}
char s1[100];
while(~scanf("%s",s1))
{
int flag=Find(s1);
//cout<<flag;
if(flag)
printf("%s\n",c[flag]);
else
printf("eh\n");
}
}

poj 2503 哈希 Map 字典树的更多相关文章

  1. POJ 2503 Babelfish(map,字典树,快排+二分,hash)

    题意:先构造一个词典,然后输入外文单词,输出相应的英语单词. 这道题有4种方法可以做: 1.map 2.字典树 3.快排+二分 4.hash表 参考博客:[解题报告]POJ_2503 字典树,MAP ...

  2. POJ 3376 Finding Palindromes EX-KMP+字典树

    题意: 给你n个串串,每个串串可以选择和n个字符串拼接(可以自己和自己拼接),问有多少个拼接后的字符串是回文. 所有的串串长度不超过2e6: 题解: 这题由于是在POJ上,所以string也用不了,会 ...

  3. [POJ] #1002# 487-3279 : 桶排序/字典树(Trie树)/快速排序

    一. 题目 487-3279 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 274040   Accepted: 48891 ...

  4. POJ 3764 (异或+字典树)

    早就听过用字典树求异或最大值,然而没做过.发现一碰到异或的题就GG,而且因为以前做过的一道类似的题(事实上并不类似)限制了思路,蠢啊= =. 题意:一棵带权的树,求任意两点间路径异或的最大值. 题解: ...

  5. poj 3764 The xor-longest Path(字典树)

    题目链接:poj 3764 The xor-longest Path 题目大意:给定一棵树,每条边上有一个权值.找出一条路径,使得路径上权值的亦或和最大. 解题思路:dfs一遍,预处理出每一个节点到根 ...

  6. 哈希与字典树与KMP

    hash讲解 主要记录hash的公式: ; i<=len; i++) { Hash[i]=(Hash[i-]*)%mod)%mod; } 求hash的公式是这个,怎么求一小段的hash值呢? ; ...

  7. J - What Are You Talking About(map,字典树)

    题意:上部分是单词表,下部分是句子,翻译句子.START开始,END结束. 思路:简单字典树. Ignatius is so lucky that he met a Martian yesterday ...

  8. poj 2001:Shortest Prefixes(字典树,经典题,求最短唯一前缀)

    Shortest Prefixes Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 12731   Accepted: 544 ...

  9. POJ 3764 The xor-longest Path ( 字典树求异或最值 && 异或自反性质 && 好题好思想)

    题意 : 给出一颗无向边构成的树,每一条边都有一个边权,叫你选出一条路,使得此路所有的边的异或值最大. 分析 : 暴力是不可能暴力的,这辈子不可能暴力,那么来冷静分析一下如何去做.假设现在答案的异或值 ...

随机推荐

  1. glEnable(GL_DEPTH_TEST)作用

    glEnable(GL_DEPTH_TEST): 用来开启更新深度缓冲区的功能,也就是,如果通过比较后深度值发生变化了,会进行更新深度缓冲区的操作.启动它,OpenGL就可以跟踪再Z轴上的像素,这样, ...

  2. OpenCV图像处理篇之边缘检測算子

    3种边缘检測算子 灰度或结构等信息的突变位置是图像的边缘,图像的边缘有幅度和方向属性.沿边缘方向像素变化缓慢,垂直边缘方向像素变化剧烈.因此,边缘上的变化能通过梯度计算出来. 一阶导数的梯度算子 对于 ...

  3. java枚举在android项目应用

    今天修复一个公司非常早曾经的android应用功能,里面的代码逻辑已经全然错乱,然后发现返回的数据全然不正确了.然后修复了整整两天.然后我又一次整理了一遍,重构就算不上了. 然后就用上了枚举. 什么是 ...

  4. MAC 文件加密

    MAC 文件加密 (2011-10-08 00:08:52) 标签: 杂谈 分类: MAC技巧篇 我们都有一些私密的文件需要保存,在苹果操作系统下,如何为这些文件或文件夹设置密码呢? 利用系统自带的创 ...

  5. thinkphp跨模块调用

    thinkphp跨模块调用 跨模块调用模板 return $view->fetch('admin@user/add'); 全路径模板调用: return $view->fetch(APP_ ...

  6. CSS的水平居中和垂直居中解决方案

    在写CSS样式的时候,有时为了美观,会添加水平居中和垂直居中,这时候你有可能会遇到很棘手的问题,有些水平居中和垂直居中的属性添加上去完全没反应,下面给大家列举一些CSS水平居中和垂直居中的终极解决方案 ...

  7. 开启Windows 7远程桌面功能的做法

    作者:朱金灿 来源:http://blog.csdn.net/clever101 本设置方法同样适用用Vista和Windows Server 2008. 1.依次点击"开始"菜单 ...

  8. XML之序列化C#实体类,DataTable,List

    1. static void Main(string[] args) { #region 实体类 Request patientIn = new Request(); patientIn.System ...

  9. 系统管理员的 SELinux 指南:这个大问题的 42 个答案

    安全.坚固.遵从性.策略是末世中系统管理员的四骑士.除了我们的日常任务之外 —— 监控.备份.实施.调优.更新等等 —— 我们还需要负责我们的系统安全.即使这些系统是第三方提供商告诉我们该禁用增强安全 ...

  10. 学习《Python数据科学手册》高清中文PDF+高清英文PDF+代码

    如果有一定的数据分析与机器学习理论与实践基础,<Python数据科学手册>这本书是绝佳选择. 是对以数据深度需求为中心的科学.研究以及针对计算和统计方法的参考书.很友好实用,结构很清晰.但 ...