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. linux lazarus 连接mssqlserver

    1 . 从https://www.freetds.org/ 下载驱动源文件 2. 参照 https://www.freetds.org/userguide/config.htm 内容编译 3. 启动l ...

  2. BZOJ 4517: [Sdoi2016]排列计数 错排 + 组合

    从 $n$ 个数中选 $m$ 个不错排,那就是说 $n-m$ 个数是错排的. 用组合数乘一下就好了. Code: #include <cstdio> #include <algori ...

  3. 打开ubuntu终端,没有用户名显示,只剩下光标在闪

    总结起来就是bash损坏了.bash是用户与操作系统内核交互的工具.bash损坏,则用户无法操作计算机. 推荐两个帖子: https://blog.csdn.net/u011128515/articl ...

  4. Spring Boot教程(六)在springboot中验证表单信息

    构建工程 创建一个springboot工程,由于用到了 web .thymeleaf.validator.el,引入相应的起步依赖和依赖,代码清单如下: <dependencies> &l ...

  5. 源码阅读-Kingfisher

    最后更新:2018-01-16 使用教程: 官方的链接 使用 Kingfisher 处理网络图片的读取与缓存 1. 开始使用 桥接 KingFisher, 利用 KingfisherCompatibl ...

  6. FP AUTO节点ZPP002M执行卡住解决

    正常情况下,不到一分钟即可执行完ZPP002M节点 异常情况下,超过十分钟都没有响应 再等待只会影响FP的执行时间,影响后续的节点,解决办法是将正在执行的JOB STOP掉 再到服务器上将该节点重新执 ...

  7. sqli-labs(32)

    0x1查看源代码 (1)代码关键点 很明显,代码中利用正则匹配将 [ /,'," ]这些三个符号都过滤掉了 preg_replace 0x2 宽字符注入 (1)前言 在mysql中,用于转义 ...

  8. 用命令行编译运行java文件的乱码问题

    之前在写的时候没有遇到过这个问题,用惯了eclipse之后突然用Notepad++就出现乱码了 我在编写的时候 指定Noepad++的编码是 UTF-8编码,然后进入命令行,编译的时候就出现了乱码 然 ...

  9. vue树形菜单

    vue树形菜单 由于项目原因,没有使用ui框架上的树形菜单,所以自己动手并参考大佬的代码写了一个树形菜单的组件,话不多说,直接上代码.html代码js代码直接调用api 把请求到的数据直接赋值给per ...

  10. linux系统/var目录的作用

    linux系统/var目录的作用 一.总结 一句话总结: 1.如果/usr是安装时会占用较大硬盘容量目录,那么/var就是在系统运行后才会渐渐占用硬盘容量的目录. 2.因为var目录主要针对常态性变动 ...