Babelfish 分类: 哈希 2015-08-04 09:25 2人阅读 评论(0) 收藏
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) 收藏的更多相关文章
- *** glibc detected *** malloc(): memory corruption 分类: C/C++ Linux 2015-05-14 09:22 37人阅读 评论(0) 收藏
*** glibc detected *** malloc(): memory corruption: 0x09eab988 *** 发现是由于memset越界写引起的. 在Linux Server上 ...
- 修改MS SQL忽略大小写 分类: SQL Server 数据库 2015-06-19 09:18 34人阅读 评论(0) 收藏
第一步:数据库->属性->选项->限制访问:SINGLE_USER 第二步:ALTER DATABASE [数据库名称] collate Chinese_PRC_CI_AI 第三步: ...
- visual studio2010复制粘贴源代码到Word时乱码问题 分类: C# 2014-11-28 09:25 687人阅读 评论(0) 收藏
问题描述: visual studio2010 拷贝源代码的时候,在windows自带的写字板和word2010上,粘贴的时候中文字符都会变成乱码. 如: "该用户已经被成功添加" ...
- 学习金字塔 分类: T_TALENT 2014-05-21 09:25 331人阅读 评论(0) 收藏
学习金字塔是美国缅因州的国家训练实验室研究成果,它用数字形式形象显示了:采用不同的学习方式,学习者在两周以后还能记住内容(平均学习保持率)的多少.它是一种现代学习方式的理论.最早它是由美国学者.著名的 ...
- 架构师速成6.7-设计开发思路-uml 分类: 架构师速成 2015-07-29 18:25 157人阅读 评论(0) 收藏
uml是什么东西?统一建模语言,一门语言,是用来进行软件设计的一门语言. 其实一门语言的诞生并不伟大,让大多数人都使用才足够伟大.uml就是一门伟大的语言,因为目前软件设计的唯一语言就是它. UML其 ...
- sscanf 函数 分类: POJ 2015-08-04 09:19 4人阅读 评论(0) 收藏
sscanf 其实很强大 分类: 纯C技术 技术笔记 2010-03-05 16:00 12133人阅读 评论(4) 收藏 举报 正则表达式stringbuffercurlgoogle 最近在做日志分 ...
- 哈希-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: ...
- 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 ...
- iOS开源库--最全的整理 分类: ios相关 2015-04-08 09:20 486人阅读 评论(0) 收藏
youtube下载神器:https://github.com/rg3/youtube-dl 我擦咧 vim插件:https://github.com/Valloric/YouCompleteMe vi ...
随机推荐
- Swift游戏实战-跑酷熊猫 08 产生源源不断的移动平台
原理 代码实现 这节内容我们一起学习下平台的生产算法. 要点: 何时生成新的平台: 当上一个平台的右边完全进入场景的时候,就可以生成新的平台类. 如何知道上一个平台完全进入场景: 主场景中有个变量la ...
- Leetcode: UTF-8 Validation
A character in UTF8 can be from 1 to 4 bytes long, subjected to the following rules: For 1-byte char ...
- SQL 自动增长 identity
create table Users( id ,),--id 从10000开始,增加长度为1 name ), ); --执行三次这个语句 insert into Users values('小昆虫') ...
- poj 1176 Party Lamps
http://poj.org/problem?id=1176 Party Lamps Time Limit: 1000MS Memory Limit: 10000K Total Submissio ...
- [原创]java WEB学习笔记56:Struts2学习之路---Struts 版本的 登录 demo
本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...
- SNMP ber 编码
5.1 标识域(tag)的编码规则 标识域指明数据的类型,占用1个字节,常见的类型有:BOOL(0x01);INT(0x02);OCTSTR(0x04);NULL(0x05);OBJID(0x06); ...
- demo15 AlertDialog
Dialog dialog = new AlertDialog.Builder(this).setTitle("对话框").setMessage("this is msg ...
- 开启xp_cmdshell
--打开xp_cmdshell EXEC sp_configure 'show advanced options', 1GORECONFIGUREGOEXEC sp_configure 'xp_cmd ...
- wireshark抓包
ip.addr==IP地址(192.168.1.100)&& http
- javascript中字符串格式json如何转化成json对象
什么是JSON JSON(JavaScript Object Notation)是一种优美的JavaScript对象创建方法.JSON也是一种轻量级数据交换格式.JSON非常易于人阅读与编写,同时利于 ...