Babelfish
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 32988   Accepted: 14189

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

Waterloo local 2001.09.22
输入一个字典。前面一个单词和后面的单词映射。问给出的单词有没有相应的,有输出,没有,输出eh
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
struct node{
int flag ;
node *next[27] ;
} *head;
node *getnode()
{
node *p = new node ;
int i ;
for(i = 0 ; i < 27 ; i++)
p->next[i] = NULL ;
p->flag = -1 ;
return p ;
}
void gettree(node *p,char *s,int m)
{
int i , k , l = strlen(s);
for(i = 0 ; i < l ; i++)
{
k = s[i] - 'a' ;
if( p->next[k] == NULL )
p->next[k] = getnode();
p = p->next[k] ;
}
p->flag = m ;
}
int f(node *p,char *s)
{
int i , k , l = strlen(s) ;
for(i = 0 ; i < l ; i++)
{
k = s[i] - 'a' ;
if( p->next[k] == NULL )
return -1 ;
p = p->next[k] ;
}
return p->flag;
}
char s1[110000][12] , s2[110000][12] , s[30] ;
int main()
{
int i = 0 , j , l , k ;
head = getnode();
while(1)
{
gets(s);
if(s[0] == '\0')
break;
sscanf(s,"%s %s", s1[i], s2[i]);
gettree(head,s2[i],i);
i++ ;
}
while(gets(s)!=NULL)
{
if(s[0] == '\0')
break;
k = f(head,s);
if(k == -1)
printf("eh\n");
else
printf("%s\n", s1[k]);
}
return 0;
}

版权声明:转载请注明出处:http://blog.csdn.net/winddreams

poj2503--Babelfish(特里一水)的更多相关文章

  1. POJ2503——Babelfish(map映射+string字符串)

    Babelfish DescriptionYou have just moved from Waterloo to a big city. The people here speak an incom ...

  2. POJ2503 Babelfish map或者hash_map

    POJ2503 这是一道水题,用Map轻松AC. 不过,可以拿来测一下字符串散列, 毕竟,很多情况下map无法解决的映射问题需要用到字符串散列. 自己生成一个质数, 随便搞一下. #include&l ...

  3. POJ2503——Babelfish

    Description You have just moved from Waterloo to a big city. The people here speak an incomprehensib ...

  4. POJ2503 Babelfish

    题目链接. 分析: 应当用字典树,但stl的map做很简单. #include <iostream> #include <cstdio> #include <cstdli ...

  5. POJ2503(Babelfish)--简单字典树

    思路:就是用一个字典树翻译单词的问题,我们用题目中给出的看不懂的那些单词建树,这样到每个单词的叶子结点中存放原来对应的单词就好. 这样查询到某个单词时输出叶子结点存的就行,查不到就"en&q ...

  6. poj_2503(map映射)

    题目链接poj2503 Babelfish Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 38820   Accepted: ...

  7. POJ2503:Babelfish

    浅谈\(Trie\):https://www.cnblogs.com/AKMer/p/10444829.html 题目传送门:http://poj.org/problem?id=2503 \(Trie ...

  8. Babelfish(二分查找,字符串的处理略有难度,用sscanf输入)

    Babelfish Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 28581   Accepted: 12326 题目链接: ...

  9. poj 2503:Babelfish(字典树,经典题,字典翻译)

    Babelfish Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 30816   Accepted: 13283 Descr ...

随机推荐

  1. 【桌面虚拟化】之三 Persistent vs NonP

    作者:范军 (Frank Fan) 新浪微博:@frankfan7 在[桌面虚拟化]之二类型及案例中我们探讨了桌面虚拟化的两种架构,HostedVirtual Desktop (VDI) 和 Publ ...

  2. vs2010 正式版官方下载地址

    北京时间2010年4月12日12:00,微软Visual Studio 2010 正式版提供官方下载,眼下有三个版本号,Professional/Premium/Ultimate. 注意原页面的链接R ...

  3. 微软提供了三个核心服务:Windows+Office 365+Azure

    微软提供了三个核心服务:Windows+Office 365+Azure 英语新闻来源:http://techcrunch.com/2014/11/10/microsofts-ceo-breaks-d ...

  4. 在Ubuntu上为Android系统编写Linux内核驱动程序

    文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/6568411 在智能手机时代,每个品牌的手机都有 ...

  5. Hacker(15)----嗅探原理

    嗅探指窃听网络中流经的数据包,这里的网络一般指用集线器或路由器组建的局域网.通过嗅探并解析数据包,便可知道数据包中的信息,一旦含有账户密码等隐私信息就可能造成个人资金损失. 嗅探数据包无法通过输入命令 ...

  6. Eclipse安装Vim——viPlugin插件

    1.下载viPlugin: http://www.viplugin.com/files/viPlugin_2.14.0.zip 2.安装 解压后有两个文件夹: features 和 plugins 把 ...

  7. ListHelper

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Data; ...

  8. windows2008无线网卡和.net3.5安装

    今天在联想T420S笔记本上安装windows2008标准版,安装完成后部分驱动软件不能安装,要求.net framework3.5,下载.net3.5安装时提示应该用角色管理器安装. 根据提示打开服 ...

  9. 内存操作相关内核 API 的使用

    1.RtlCopyMemory .RtlCopyBytes.RtlMoveMemory: 2.RtlZeroMemory.RtlFillMemory: 3.RtlEqualMemory: 4.ExAl ...

  10. Wordpress更换主题之后出错

    今天吃完午饭,休息休息,最近搞了一下google adsense,不过最终的审核没通过,我想会不会是界面不好看呢,饭后就在电脑旁,更换了几个wordpress主题,我的博客使用wordpress搭建的 ...