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. 算法笔记_099:蓝桥杯练习 算法提高 排列数(Java)

    目录 1 问题描述 2 解决方案   1 问题描述 问题描述 0.1.2三个数字的全排列有六种,按照字母序排列如下: 012.021.102.120.201.210 输入一个数n 求0~9十个数的全排 ...

  2. OpenERP(odoo)开发实例之搜索检索过去3个月的数据

    转自:http://www.chinamaker.net/ OpenERP(odoo)开发实例之搜索过滤:检索过去3个月的数据 解决这个问题的重点在于 relativedelta 的应用 示例代码如下 ...

  3. RSA/DSA 密钥的工作原理

    下面从整体上粗略的介绍了 RSA/DSA 密钥的工作原理.让我们从一种假想的情形开始,假定我们想用 RSA 认证允许一台本地的 Linux 工作站(称作 localbox)打开 remotebox 上 ...

  4. Python爬虫碎碎念

    最近领导给了一个任务,从单位的数据库里面导出所有的数据,存到本地excel表格.我就想,这不挺简单的么,给我数据库的密码账户,几条语句搞定. 结果让人大失所望,单位数据库只能通过后台管理系统查看,平台 ...

  5. Hibernate 第一个体验程序

    首先要导入包,将下载的hibernate所有required包导入,将下载的hibernate用来写log的slf4j的api和nopjar包导入,将下载的mysql链接引擎jar包导入. 然后新建j ...

  6. SSI整合 示例

    sql语句 create table user_c (id varchar(10) primary key,name varchar(20),age int ,address varchar(30); ...

  7. 【前端】HTML

    一.HTML介绍 Web服务本质 import socket sk = socket.socket() sk.bind(("127.0.0.1", 8080)) sk.listen ...

  8. 【java设计模式】之 单例(Singleton)模式

    1. 单例模式的定义 单例模式(Singleton Pattern)是一个比較简单的模式.其原始定义例如以下:Ensure a class has only one instance, and pro ...

  9. WebSocket遇到的一些问题

    一 .Nginx配置websocket   为了解决Nginx转发不能进行websocket通信问题 将nginx配置文件添加如下内容:   map $http_upgrade $connection ...

  10. MVC & Entity Framework(2)- controller、Models单独DLL

    继上一篇MVC & Entity Framework(1)- 开发环境之后,已经很久没更新了.接下来记录一下怎么把MVC中的controller单独拆为一个类库,然后在web项目中引用.另外, ...