1253: Problem C: Babelfish

时间限制: 1 Sec  内存限制: 128 MB
提交: 14  解决: 3
[提交][状态][讨论版]

题目描述

Problem C: Babelfish

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 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 is the message translated to English, one word per line. Foreign words not in the dictionary should be translated as "eh".

输入

 

输出

 

样例输入

dog ogday
cat atcay
pig igpay
froot ootfray
loops oopslay atcay
ittenkay
oopslay

样例输出

cat
eh
loops
#include<iostream>
#include<cstring>
#include<cstdio> using namespace std;
const int N = + ; struct node{
int v;
struct node *next[];
}*T; node *newnode(){
node *p = new node;
for(int i = ; i < ; i++) p -> next[i] = NULL;
return p;
} void Insert(node *p, char *str, int v){
int c, len = strlen(str);
for(int i = ; i < len; i++){
if(!islower(str[i])) continue;
c = str[i] - 'a';
if(p -> next[c] == NULL) p -> next[c] = newnode();
p = p -> next[c];
}
p -> v = v;
} int Query(node *p, char *str){
int c, len = strlen(str);
for(int i = ; i < len; i++){
if(!islower(str[i])) continue;
c = str[i] - 'a';
if(p -> next[c] == NULL) return ;
p = p -> next[c];
}
return p -> v;
}
char dic[N][], str[];
int main(){
int cur = ;
T = newnode();
while( ++cur ){
fgets(str, , stdin);
if(isspace(str[])) break;
sscanf(str, "%s %s", dic[cur], str);
Insert(T, str, cur);
}
while(fgets(str, , stdin) != NULL){
if(isspace(str[])) break;
cur = Query(T, str);
printf("%s\n", cur? dic[cur]: "eh");
}
}
 

HNUSTOJ-1253 Babelfish(字典树)的更多相关文章

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

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

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

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

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

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

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

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

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

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

  6. POJ2503(Babelfish)--简单字典树

    思路:就是用一个字典树翻译单词的问题,我们用题目中给出的看不懂的那些单词建树,这样到每个单词的叶子结点中存放原来对应的单词就好. 这样查询到某个单词时输出叶子结点存的就行,查不到就"en&q ...

  7. 数据结构~trie树(字典树)

    1.概述 Trie树,又称字典树,单词查找树或者前缀树,是一种用于快速检索的多叉树结构,如英文字母的字典树是一个26叉树,数字的字典树是一个10叉树. 我理解字典树是看了这位大佬博客.还不了解字典树的 ...

  8. poj 2503 哈希 Map 字典树

    Babelfish Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 36967   Accepted: 15749 Descr ...

  9. 萌新笔记——用KMP算法与Trie字典树实现屏蔽敏感词(UTF-8编码)

    前几天写好了字典,又刚好重温了KMP算法,恰逢遇到朋友吐槽最近被和谐的词越来越多了,于是突发奇想,想要自己实现一下敏感词屏蔽. 基本敏感词的屏蔽说起来很简单,只要把字符串中的敏感词替换成"* ...

随机推荐

  1. angular-seed — AngularJS种子项目

    AngularJS Seed 是典型 AngularJS web 应用的应用骨架,可以快速启动你的 AngularJS webapp 项目和这些项目的开发环境. AngularJS Seed 包括一个 ...

  2. ForkJoinPool及并行流解析

    parallelStream原理. parallelStream是并行流,依赖jdk1.7出现的Fork/Join框架. Fork/Join框架的核心是工作窃取(work-stealing)算法.那么 ...

  3. BZOJ 4769: 超级贞鱼 逆序对 + 归并排序

    手画几下序列的变换后发现逆序对数是恒定的,故只需对第 $0$ 年求逆序对即可. 树状数组会 $TLE$ 的很惨,需要用到归并排序来求逆序对. 其实就是省掉了一个离散化的时间,估计能比树状数组快一半的时 ...

  4. [Noip模拟题]宠物之战senso

    Description 众所周知,moreD的宠物已经被moreD奴役得体无完肤.这只宠物实在忍无可忍,把自己每天走魔法树的经历告诉了 自己的宠物.同时他还说明了自己爬树是多么地慢,以至于moreD每 ...

  5. OI多项式 简单学习笔记

    咕咕咕 先开个坑(其实是存模板来了) 一些特别简单的前置东西qwq 复数的计算 复数相加:向量相加,复数相乘.复数相乘:模长相乘,旋转量相加(就是复平面坐标轴逆时针旋转的角度) (当然也可以直接使用c ...

  6. 目标检测Object Detection概述(Tensorflow&Pytorch实现)

    1999:SIFT 2001:Cascades 2003:Bag of Words 2005:HOG 2006:SPM/SURF/Region Covariance 2007:PASCAL VOC 2 ...

  7. [BZOJ2729]:[HNOI2012]排队(组合数学)

    题目传送门 题目描述 某中学有n名男同学,m名女同学和两名老师要排队参加体检.他们排成一条直线,并且任意两名女同学不能相邻,两名老师也不能相邻,那么一共有多少种排法呢?(注意:任意两个人都是不同的) ...

  8. android intent调用系统camera

    利用android的camera通常有两种方式:利用intent调用系统的camera,或者结合surfaceview实现自己定制的camera.先分别对这两种方法说明如下: 一.使用系统自配的cam ...

  9. Java并发编程的艺术笔记(一)——volatile和syncronized关键字

    一.线程间的通信 volatile和syncronized关键字 volatile 修饰变量,告知任何对该变量的访问必须从共享内存获取,对它的改变必须同步刷新至共享内存,由此保证可见性. syncro ...

  10. 移动端复制当前页面链接(URL)分享

    注释:在移动端想做一个复制当前URL类似于分享的功能 示例: <span class="share_btn"><img src="../resource ...