Time Limit: 3000MS Memory Limit: 65536K
Total Submissions: 29059 Accepted: 12565

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 题意:给一个字典,输入若干个字符串,问再字典中与它对应的字符串,若没有输出“eh”;

 #include<stdio.h>
#include<string.h>
#include<stdlib.h>
char s1[][],s2[][]; struct node
{
int flag;
struct node *next[];
};
struct node* creat()
{
struct node *p = (struct node *)malloc(sizeof(struct node));
p->flag = ;
for(int i = ; i < ; i++)
p->next[i] = NULL;
return p;
} void insert(struct node *p, char s[],int cnt)
{
for(int i = ; s[i]; i++)
{
if(p->next[s[i]-'a'] == NULL)
p->next[s[i]-'a'] = creat();
p = p->next[s[i]-'a'];
}
p->flag = cnt;
}
int search(struct node *p, char s[])
{
for(int i = ; s[i]; i++)
{
if(p->next[s[i]-'a'] == NULL)
return -;
p = p->next[s[i]-'a'];
}
return p->flag;
}
int main()
{
char s[],str[];
int cnt = ;
struct node *root;
root = creat();
while(gets(s))
{
if(strcmp(s,"") == )
break;
sscanf(s,"%s %s",s1[cnt],s2[cnt]);
insert(root,s2[cnt],cnt);
cnt++;
}
while(scanf("%s",str)!= EOF)
{
int f = search(root,str);
if(f == -)
printf("eh\n");
else printf("%s\n",s1[f]);
}
return ;
}
												

poj 2503 Babelfish(字典树哈希)的更多相关文章

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

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

  2. poj 2503 Babelfish(字典树或着STL)

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

  3. Colored Sticks (字典树哈希+并查集+欧拉路)

    Time Limit: 5000MS   Memory Limit: 128000K Total Submissions: 27704   Accepted: 7336 Description You ...

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

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

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

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

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

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

  7. poj 3007 Organize Your Train part II(静态字典树哈希)

    Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6700 Accepted: 1922 Description RJ Freigh ...

  8. POJ 2503 Babelfish

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

  9. Watto and Mechanism CodeForces - 514C (字典树,哈希)

    大意: 给定字符串集$S$, 每次询问给出字符串$a$, 求$S$中是否存在一个字符串恰好与$a$相差一个字符. 直接建字典树暴力复杂度是$O(n\sqrt{n})$, 也可以用set维护所有哈希值, ...

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

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

随机推荐

  1. spring mvc DispatcherServlet详解之二---request通过Controller获取ModelAndView过程

    整个spring mvc的架构如下图所示: 上篇文件讲解了DispatcherServlet通过request获取控制器Controller的过程,现在来讲解DispatcherServletDisp ...

  2. FaceBook要在视频领域打败YouTube?

    据<纽约时报>报道,FaceBook正在探索一项新的策略来直接把音乐视频嵌入到用户的News Feeds中.目前,具有代表性的视频网站有YouTube和Vimeo,它们可以在社交网络上分享 ...

  3. Asp.net Mvc 第二回 UrlRouting

    一.什么是UrlRouting 你可以使用UrlRouting来配置一些URL的映射,使用户可以按你的规则来访问网站. 使用UrlRouting,一定要规定URL模式,它包括一个位置标识,它将在你请求 ...

  4. 详细分析Orchard的Content、Drivers, Shapes and Placement 类型

    本文原文来自:http://skywalkersoftwaredevelopment.net/blog/a-closer-look-at-content-types-drivers-shapes-an ...

  5. angularjs ngTable -Custom filter template-calendar

    jsp页面: <script type="text/ng-template" id="path/to/your/filters/top-Date-One.html& ...

  6. iOS 从网络获取son并解析

    NSString* GXURL = PURL; GXURL = [GXURL stringByAppendingString:@"/index.php/Api/android_getRank ...

  7. this的一个作用 当前对象

    class Person{ String name="小花"; int age=19; void eat(){  System.out.println("在吃饭" ...

  8. Magento 2.0 安装

    环境: 直接升到最新版PHP5.6.x 刚才开MAC OS PHP 5.5  CENTOS PHP 5.5  composer install  依懒包错误.反复安装组件.还是不行.后来决定重新编释最 ...

  9. 总结几种C#窗体间通讯的处理方法

    摘要:本文介绍了C#窗体间通讯的几种处理方法,即传值.继承.事件回调,希望对大家有用. http://www.cnblogs.com/jara/p/3439603.html 应用程序开发中,经常需要多 ...

  10. python模块之socket

    43.python模块之socket:       Python在网络通讯方面功能强大,学习一下Socket通讯的基本方式 UDP通讯: Server: import socket port=8081 ...