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. How to uninstall (remove) JAVA from OS X Lion

    Open terminal (Applications -> Utilities -> Terminal) To remove JVM enter folowing: sudo rm -r ...

  2. PHP性能优化学习笔记--PHP周边性能优化--来自慕课网Pangee http://www.imooc.com/learn/205

    PHP一般运行于Linux服务器中,周边主要包括:Linux运行环境.文件存储.数据库.缓存.网络 常见PHP场景的开销次序: 读写内存<<读写数据库(使用内存作为缓存.异步处理)< ...

  3. OCP-1Z0-051-题目解析-第6题

    6. Examine the structure of the SHIPMENTS table: name                    Null        Type PO_ID      ...

  4. 针对各主流数据mysql、sqlserver、oracle中文乱码问题。

    针对各主流数据mysql.sqlserver.oracle当以编码格式gbk存放数据时,要注意字符串类型的字段,要采用宽字符串nvarchar存放,前提是当你的应用程序是utf8编码,而数据库是gbk ...

  5. jquery 底部导航透明度变化

    如果滚动条到达底部,footer-nav 的透明度为1,否则为0.8: html <div class="footer-nav" id="footer"& ...

  6. js图片放大镜 可动态更换图片

    现仅已.NET为例,HTML代码如下 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > & ...

  7. PagedList 分页

    @using PagedList.Mvc;@model PagedList.IPagedList<MvcApplicationBootStramp.Models.Person> @{    ...

  8. 使用do...while的方法输入一个月中所有的周日

    do{ var date = Number(prompt('请输入一个月的总天数')); var start = (prompt('请输入一个月的一号是周几')); for(var i=0;i< ...

  9. 玩转Firefox侧栏

    偶然看到煎蛋网的"玩转firefox侧栏",才注意到它. Firefox侧栏有啥不一样? Firefox可以在侧栏中打开网页. 于是,一系列玩法就出来了... 侧栏打开在线应用 G ...

  10. HQL和Criteria(转)

    HQL(Hibernate Query Language)        面向对象的查询语言,与SQL不同,HQL中的对象名是区分大小写的(除了JAVA类和属性其他部分不区分大小写):HQL中查的是对 ...