Babelfish
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 35828   Accepted: 15320

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

field=source&key=Waterloo+local+2001.09.22" style="text-decoration:none">Waterloo local 2001.09.22

STL相同秒杀 我就怀疑字典树有个鸡毛用,測试例子太少了吧!

STL:

#include<iostream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<string.h>
#include<cctype>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
using namespace std; int main()
{
string str;map<string,string >cnt;
while(getline(cin,str)&&str[0]!=0)
{
int loc=str.find(" ");
cnt[str.substr(loc+1,str.size()-loc-1)]=str.substr(0,loc);
}
while(cin>>str)
{
if(cnt.count(str))
cout<<cnt[str]<<endl;
else
cout<<"eh"<<endl;
}
return 0;
}

字典树:

#include<iostream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<string.h>
#include<cctype>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
using namespace std;
typedef struct NodeType
{
struct NodeType * child[26];
char word [11];
int isWord;
NodeType()
{
memset(child,NULL,sizeof(child));
isWord=0;
}
} Node; void insertWord(Node *node,char *wo,char *wt)
{
int id;
while(*wt)
{
id=*wt-'a';
if(node->child[id]==NULL)
node->child[id]=new Node();
node=node->child[id];
wt++;
}
node->isWord=1;
strcpy(node->word,wo);
} char * searchWord(Node * node,char *wd)
{
char *noWord="eh";
int id;
while(*wd)
{
id=*wd-'a';
if(node->child[id]==NULL)
return noWord;
node=node->child[id];
wd++;
}
if(node->isWord)
return node->word;
else
return noWord;
} int main()
{
char cnt[40],dict[40],buf[40];
Node * node=new Node;
while(gets(buf)&&buf[0]!=0)
{
int i=0;
for(; buf[i]!=32; i++)
cnt[i]=buf[i];
cnt[i]=0;
int j;
for(++i,j=0; buf[i]; i++,j++)
dict[j]=buf[i];
dict[j]=0;
insertWord(node,cnt,dict);
}
while(scanf("%s",cnt)!=EOF)
{
char *word = searchWord(node,cnt);
printf("%s\n",word);
}
return 0;
}

poj 2503 Babelfish(字典树或着STL)的更多相关文章

  1. poj 2503 Babelfish(字典树或map或哈希或排序二分)

    输入若干组对应关系,然后输入应该单词,输出对应的单词,如果没有对应的输出eh 此题的做法非常多,很多人用了字典树,还有有用hash的,也有用了排序加二分的(感觉这种方法时间效率最差了),这里我参考了M ...

  2. poj 2503 Babelfish(Map、Hash、字典树)

    题目链接:http://poj.org/bbs?problem_id=2503 思路分析: 题目数据数据量为10^5, 为查找问题,使用Hash或Map等查找树可以解决,也可以使用字典树查找. 代码( ...

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

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

  4. POJ 2503 Babelfish(map,字典树,快排+二分,hash)

    题意:先构造一个词典,然后输入外文单词,输出相应的英语单词. 这道题有4种方法可以做: 1.map 2.字典树 3.快排+二分 4.hash表 参考博客:[解题报告]POJ_2503 字典树,MAP ...

  5. POJ 2503 Babelfish

    Babelfish Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 28766 Accepted: 12407 Descripti ...

  6. poj 2513(欧拉路径+字典树映射)

    题目链接:http://poj.org/problem?id=2513 思路:题目还是很简单的,就是判断是否存在欧拉路径,我们给每个单词的头和尾映射序号,统计度数.对于给定的无向图,当且仅当图连通并且 ...

  7. POJ 1451 - T9 - [字典树]

    题目链接:http://bailian.openjudge.cn/practice/1451/ 总时间限制: 1000ms 内存限制: 65536kB 描述 Background A while ag ...

  8. POJ 2513 【字典树】【欧拉回路】

    题意: 有很多棒子,两端有颜色,告诉你两端的颜色,让你把这些棒子拼接起来要求相邻的接点的两个颜色是一样的. 问能否拼接成功. 思路: 将颜色看作节点,将棒子看作边,寻找欧拉通路. 保证图的连通性的时候 ...

  9. poj 2503 Babelfish(字典树哈希)

    Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 29059 Accepted: 12565 Description You hav ...

随机推荐

  1. C#中使用正则

      using System.Text.RegularExpressions;           private void button1_Click(object sender, EventArg ...

  2. PgSql备份pg_dump与还原手记pg_restore(转)

    可以直接跳转至最后面的示例进行查看 真没有想到,以前一直是PostgreSQL使用者,突然需要库移植又成了头一招了!原来它与mysql命令行操作区别还挺大. 不用怕,但绝对要细心,因为数据库操作是网站 ...

  3. 文本域textarea

      文本域 CreateTime--2017年5月23日15:12:08Author:Marydon 二.文本域 (一)语法 <textarea></textarea> (二) ...

  4. (四)Oracle学习笔记—— 常见函数

    1. 字符串类型及函数 字符类型分 种,char(n) .varchar(n).varchar2(n) : char(n)固定长度字符串,假如长度不足 n,右边空格补齐: varchar(n)可变长度 ...

  5. Fragment的陷阱

    以前做过的一个项目,Fragment嵌套高德地图,当再次进入Fragment的时候,会出现奇怪的现象.嵌套的地图会出现滑动不动的情况,起先还以为是高德的bug呢,经过一番研究,终确定这是一个坑. 先对 ...

  6. C# EF更新当前实体报错 ObjectManager无法管理具有相同键值的多个对象

    原因: ObjectManager已经在跟踪此对象 更新实体前判断 if (db.Entry<T>(t).State != EntityState.Modified) db.Entry&l ...

  7. const和readonly关键字

    不知道大家对const和readonly这两个关键字的区别有什么了解,原来自己之前还真不清楚它们到底是怎么回事,那么如果你也不是很清楚的话,可以一起来探讨一下.在了解这两个关键字的时候我们先来了解一下 ...

  8. Navicat for MySQL再谈之无奈之下还是去安装Navicat Premium

    不多说,直接上干货! 首先,Navicat for MySQL没有查看数据库属性. 其次,没有这个功能多和强大,在走过一段弯路之后,果断放弃Navicat for MySQL,而使用Navicat P ...

  9. atitit.js的 字符串内容 转义  js处理html

    atitit.js的 字符串内容 转义  js处理html 1. js处理html的问题 1 2. js的 字符串内容 转义 1 2.1. 处理流程 1 3. 下面的表格列出了其余的特殊字符,这些特殊 ...

  10. matplotlib极坐标系应用之雷达图

    #!/usr/bin/env python3 #-*- coding:utf-8 -*- ############################ #File Name: test.py #Autho ...