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. Zookeeper学习记录(一):设计与实现

    概述 Zookeeper是一个分布式的.开源的分布式应用协调服务.它暴露了一组简单的基础原件,分布式应用可以在这些原件之上实现更高级别的服务,如同步.配置维护.群组.和命名.它被设计成容易编程实现的, ...

  2. C++: int和string相互转换

    假设在一个C++的程序中常常会用到int和string之间的互换.个人建议能够写成一个函数,下次用的时候直接调用就可以. #include <iostream> #include < ...

  3. hdu 4923 Room and Moor (单调栈+思维)

    题意: 给一个0和1组成的序列a,要构造一个相同长度的序列b.b要满足非严格单调,且 值为0到1的实数.最后使得  sum((ai-bi)^2)最小. 算法: 首先a序列開始的连续0和末尾的连续1是能 ...

  4. HDU 1827 Summer Holiday(Tarjan缩点)

    Problem Description To see a World in a Grain of Sand  And a Heaven in a Wild Flower,  Hold Infinity ...

  5. qemu-kvm-1.1.0源代码中关于迁移的代码分析

    这篇文档基于qemu-kvm-1.1.0源代码进行分析. 首先,源代码中的hmp-commands.hx文件里有下面内容: { .name = "migrate",/* 在moni ...

  6. html_day3

    总结学习html的第一天 表格的结构说明 <table></table> <tr></tr> <td></td> <th& ...

  7. UIWindow & UIWindowLevel详解

    一.UIWindow是一种特殊的UIView,通常在一个程序中只会有一个UIWindow,但可以手动创建多个UIWindow,同时加到程序里面.UIWindow在程序中主要起到三个作用: 1.作为容器 ...

  8. (转) launch failed.Binary not found in Linux/Ubuntu解决方案

    原地址: http://blog.csdn.net/abcjennifer/article/details/7573916 Linux下出现launch failed.Binary not found ...

  9. JavaScript 全局变量命名空间生成函数

    <script type="text/javascript"> var GLOBAL = {}; GLOBAL.namespace = function(str){ v ...

  10. 指令中 controller && controllerAs

    1, controller 他会暴露一个API,利用这个API可以在多个指令之间通过依赖注入进行通信. controller($scope, $element, $attrs, $tranclude) ...