Babelfish

Time Limit: 3000MS Memory Limit: 65536K

Total Submissions: 36398 Accepted: 15554

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.

一道哈希的题,用字典树过的,不过在输入数据的过程中却卡住了,后来在搜题解知道用sscanf()处理的,见识少啊.

#include <map>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define LL long long
#define eps 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define CRR fclose(stdin)
#define CWW fclose(stdout)
#define WW freopen("output.txt","w",stdout)
#define RR freopen("input.txt","r",stdin) using namespace std; const int MAX = 100010; char s[MAX][15],c[15]; struct node
{
int flag;
node *next[26];
}*head;
int top;
node * Creat()
{
node *p;
p=new node;
p->flag=0;
for(int i=0;i<26;i++)
{
p->next[i]=NULL;
}
return p;
}
void Build_Tree()
{
node *p=head;
int a,len=strlen(c);
for(int i=0;i<len;i++)
{
a=c[i]-'a';
if(!p->next[a])
{
p->next[a]=Creat();
}
p=p->next[a];
}
p->flag=top;//将对应单词的编号赋给它,便于查找
}
int Look()
{
node *p=head;
int a,len=strlen(c);
for(int i=0;i<len;i++)
{
a=c[i]-'a';
if(!p->next[a])
{
return 0;
}
p=p->next[a];
}
if(!p->flag)//查找不到返回零
{
return 0;
}
else
{
return p->flag;
}
}
int main()
{
head=Creat();
top=1;
int t;
char cc[30];
while(gets(cc)&&cc[0]!='\0')
{ sscanf(cc,"%s %s",s[top],c);
Build_Tree();
top++; }
while(~scanf("%s",c))
{
t=Look();
if(t)
{
printf("%s\n",s[t]);
}
else
{
printf("eh\n");
}
}
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

Babelfish 分类: 哈希 2015-08-04 09:25 2人阅读 评论(0) 收藏的更多相关文章

  1. *** glibc detected *** malloc(): memory corruption 分类: C/C++ Linux 2015-05-14 09:22 37人阅读 评论(0) 收藏

    *** glibc detected *** malloc(): memory corruption: 0x09eab988 *** 发现是由于memset越界写引起的. 在Linux Server上 ...

  2. 修改MS SQL忽略大小写 分类: SQL Server 数据库 2015-06-19 09:18 34人阅读 评论(0) 收藏

    第一步:数据库->属性->选项->限制访问:SINGLE_USER 第二步:ALTER DATABASE [数据库名称] collate Chinese_PRC_CI_AI 第三步: ...

  3. visual studio2010复制粘贴源代码到Word时乱码问题 分类: C# 2014-11-28 09:25 687人阅读 评论(0) 收藏

    问题描述: visual studio2010 拷贝源代码的时候,在windows自带的写字板和word2010上,粘贴的时候中文字符都会变成乱码. 如: "该用户已经被成功添加" ...

  4. 学习金字塔 分类: T_TALENT 2014-05-21 09:25 331人阅读 评论(0) 收藏

    学习金字塔是美国缅因州的国家训练实验室研究成果,它用数字形式形象显示了:采用不同的学习方式,学习者在两周以后还能记住内容(平均学习保持率)的多少.它是一种现代学习方式的理论.最早它是由美国学者.著名的 ...

  5. 架构师速成6.7-设计开发思路-uml 分类: 架构师速成 2015-07-29 18:25 157人阅读 评论(0) 收藏

    uml是什么东西?统一建模语言,一门语言,是用来进行软件设计的一门语言. 其实一门语言的诞生并不伟大,让大多数人都使用才足够伟大.uml就是一门伟大的语言,因为目前软件设计的唯一语言就是它. UML其 ...

  6. sscanf 函数 分类: POJ 2015-08-04 09:19 4人阅读 评论(0) 收藏

    sscanf 其实很强大 分类: 纯C技术 技术笔记 2010-03-05 16:00 12133人阅读 评论(4) 收藏 举报 正则表达式stringbuffercurlgoogle 最近在做日志分 ...

  7. 哈希-4 Values whose Sum is 0 分类: POJ 哈希 2015-08-07 09:51 3人阅读 评论(0) 收藏

    4 Values whose Sum is 0 Time Limit: 15000MS Memory Limit: 228000K Total Submissions: 17875 Accepted: ...

  8. Hdu 1507 Uncle Tom's Inherited Land* 分类: Brush Mode 2014-07-30 09:28 112人阅读 评论(0) 收藏

    Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  9. iOS开源库--最全的整理 分类: ios相关 2015-04-08 09:20 486人阅读 评论(0) 收藏

    youtube下载神器:https://github.com/rg3/youtube-dl 我擦咧 vim插件:https://github.com/Valloric/YouCompleteMe vi ...

随机推荐

  1. jquery网址

    各种分布图的插件:http://echarts.baidu.com/demo.html

  2. jsp中${param.user}不解析,原样输出。

    没加<%@ page isELIgnored="false"%>

  3. FB面经prepare: Task Schedule

    每种task都有冷却时间,比如task1执行后,要经过interval时间后才能再次执行,求总共所需时间. 用HashMap保存每一个task的下一次可以开始执行的最早时间 package TaskS ...

  4. 在Adobe AIR/AS 程序中 如何设置目录

    首先所有目录都以 "File:///"开头,无论Mac或者Windows 后面的路径 Windows: E:/WorkGround/Txt.txt  --> "Fi ...

  5. A*啦啦啦

    ...A*是个啥都不知道.. 大家注意K短路可能不存在!!!! 果然是s==t的问题……加个if(s==t) k++就A了…… 单用Dij,tle到死 原来是单向k短路........开始以为是双向的 ...

  6. sql server create foreign key

    in table design view(right click table and choose design), right click on a column, and select 'rela ...

  7. paper 55:图像分割代码汇总

    matlab 图像分割算法源码 1.图像反转 MATLAB程序实现如下:I=imread('xian.bmp');J=double(I);J=-J+(256-1); %图像反转线性变换H=uint8( ...

  8. XMLHttpRequest Level2实现跨域

    Html5提供的XMLHttpRequest Level2已经实现的跨域访问以及一些新功能 1.ie10以下版本不支持 2.在服务器端做一些小改动即可: header("Access-Con ...

  9. clock

    Prime Time中的clock分析包括: 1)Multiple clocks,clock from port/pin,virtual clock. 2)Clock network delay an ...

  10. PAT乙级 1005. 继续(3n+1)猜想 (25)

    1005. 继续(3n+1)猜想 (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 卡拉兹(Callatz ...