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. androidHandler讲解

    秒钟还没有完成的话,会收到Android系统的一个错误提示  "强制关闭".  这个时候我们需要把这些耗时的操作,放在一个子线程中,因为子线程涉及到UI更新,Android主线程是 ...

  2. C库函数笔记

    一.string.h 1.memcpy 函数原型:void *memcpy(void *dest, const void *src, size_t n); 功能:从源src所指的内存地址的起始位置开始 ...

  3. Microsoft Visual C++ 不支持long long

    Microsoft Visual C++ 不支持long long 在C/C++中,64为整型一直是一种没有确定规范的数据类型.现今主流的编译器中,对64为整型的支持也是标准不一,形态各异.一般来说, ...

  4. 练习使用jquery.并将验证强度的功能加到注册页面中

  5. iOS开发-单例模式的解读

    现在网上的有很多人写单例模式,一个很基本的东西但是版本也有很多,新人看了难免有些眼花缭乱的感觉.自己最新比较闲,也过来写一些自己的心得. 在往下看之前,我们要明白一点,那就是在什么情况下我们才要用到单 ...

  6. Eclipse 整合cvs教程及遇到的问题

    今天看着视频教程学习cvs版本管理,现在很多企业开发或许都采用了版本管理器,因为这样可以更好的进行团退开发与代码管理,所以学习一种版本管理技术还是很重要的. 最原始的独立版本管理是由两部分组成的,一个 ...

  7. C++程序设计实践指导1.15找出回文数改写要求实现

    改写要求1:用单链表实现 #include <cstdlib> #include <iostream> using namespace std; struct LinkNode ...

  8. linux下安装pdf

    官方下载地址:http://www.foxitsoftware.cn/downloads/ 问题:下载官方包以后解压,双击不能打开,也没有任何提示. 用teminal 来打开foxitreader,t ...

  9. C++----练习--bool类型作为特别的int要区别对待

    1.程序源码: #include<iostream> int main() { ; int i=condition; std::cout<<i<<std::endl ...

  10. sql helper

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