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. 同门不同类—创新Aurvana Live2/Air简评(附随身视听设备心路历程)

    (注,本文把live2/air并成一起写的,同时本人是木耳,请轻拍) 本命年各种坏东西,很是无语,终于坏到耳塞耳机了来了,之前用的拜亚DT235无缘无故就一边不响了,无奈只能扔了. 纠结了好几个月,终 ...

  2. 再谈CLR查找和加载程序集的方式

    原文:再谈CLR查找和加载程序集的方式 这是一个老问题,以前也有朋友写过一些文章介绍,但可能还不是很全面.我也多次被人问到,这里结合案例再次谈谈,希望对大家有所帮助. 本文范例代码可以通过这里下载 h ...

  3. 去掉vs2010字符串下红色波浪线

    由于在vs集成了qt库,无法提升代码. 所以下载了visual assist,然后新的问题出现了,凡是在vs中输入的字符串,下面都有红色的波浪线,而且没有错误,只是看着不舒服. 解决方法: 在VAss ...

  4. 洛谷 P1703 那个什么密码2

    P1703 那个什么密码2 题目背景 https://www.luogu.org/problem/show?pid=1079 题目描述 与原题一模一样.具体不同请见输入格式 输入输出格式 输入格式: ...

  5. Android——4.2 - 3G移植之路之 AT 通信 (四)

    在前文Android--4.2 - 3G移植之路之 reference-ril .pppd 拨号上网 (三)中分析了3G连接网络的流程,当中有说道通过AT指令建立连接, 在这里记录一下3G中的AT通信 ...

  6. 分布式架构中shiro

    分布式架构中shiro 前言:前段时间在搭建公司游戏框架安全验证的时候,就想到之前web最火的shiro框架,虽然后面实践发现在netty中不太适用,最后自己模仿shiro写了一个缩减版的,但是中间花 ...

  7. PHP date()获取某时间段以周、月、季度为粒度的时间段数组

    date()函数: PHP date()  参考:https://www.hi-docs.com/php/date.html Linux date()参考:http://www.cnblogs.com ...

  8. 【Linux下权限控制之chmod与chown命令】

    chmod 用于配置文件/目录权限 命名格式:chmod [选项] 文件/目录名 . 权限类别: r 读取 可用数字4表示 w 写入 可用数字2表示 x 执行 可用数字1表示 . 归属类别: u 属主 ...

  9. 【Django】Session

    目录 介绍 Django中操作Session @ 介绍 Cookie虽然在一定程度上解决了"保持状态"的需求,但是由于Cookie本身最大支持4096字节,以及Cookie本身保存 ...

  10. ZOJ 2562 HDU 4228 反素数

    反素数: 对于不论什么正整数x,起约数的个数记做g(x).比如g(1)=1,g(6)=4. 假设某个正整数x满足:对于随意i(0<i<x),都有g(i)<g(x),则称x为反素数. ...