HNUSTOJ-1253 Babelfish(字典树)
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(字典树)的更多相关文章
- poj 2503 Babelfish(字典树或着STL)
Babelfish Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 35828 Accepted: 15320 Descr ...
- poj 2503 Babelfish(字典树或map或哈希或排序二分)
输入若干组对应关系,然后输入应该单词,输出对应的单词,如果没有对应的输出eh 此题的做法非常多,很多人用了字典树,还有有用hash的,也有用了排序加二分的(感觉这种方法时间效率最差了),这里我参考了M ...
- poj 2503:Babelfish(字典树,经典题,字典翻译)
Babelfish Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 30816 Accepted: 13283 Descr ...
- poj 2503 Babelfish(Map、Hash、字典树)
题目链接:http://poj.org/bbs?problem_id=2503 思路分析: 题目数据数据量为10^5, 为查找问题,使用Hash或Map等查找树可以解决,也可以使用字典树查找. 代码( ...
- POJ 2503 Babelfish(map,字典树,快排+二分,hash)
题意:先构造一个词典,然后输入外文单词,输出相应的英语单词. 这道题有4种方法可以做: 1.map 2.字典树 3.快排+二分 4.hash表 参考博客:[解题报告]POJ_2503 字典树,MAP ...
- POJ2503(Babelfish)--简单字典树
思路:就是用一个字典树翻译单词的问题,我们用题目中给出的看不懂的那些单词建树,这样到每个单词的叶子结点中存放原来对应的单词就好. 这样查询到某个单词时输出叶子结点存的就行,查不到就"en&q ...
- 数据结构~trie树(字典树)
1.概述 Trie树,又称字典树,单词查找树或者前缀树,是一种用于快速检索的多叉树结构,如英文字母的字典树是一个26叉树,数字的字典树是一个10叉树. 我理解字典树是看了这位大佬博客.还不了解字典树的 ...
- poj 2503 哈希 Map 字典树
Babelfish Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 36967 Accepted: 15749 Descr ...
- 萌新笔记——用KMP算法与Trie字典树实现屏蔽敏感词(UTF-8编码)
前几天写好了字典,又刚好重温了KMP算法,恰逢遇到朋友吐槽最近被和谐的词越来越多了,于是突发奇想,想要自己实现一下敏感词屏蔽. 基本敏感词的屏蔽说起来很简单,只要把字符串中的敏感词替换成"* ...
随机推荐
- CDOJ 1059 秋实大哥与小朋友 STL(set)+离散化+BIT区间更新单点查询
链接: A - 秋实大哥与小朋友 Time Limit:1000MS Memory Limit:65535KB 64bit IO Format:%lld & %llu Subm ...
- CF Round #569 Div2(contest1180)
比赛链接:http://codeforces.com/contest/1180 Problem A 题意:给出n,问方块数.看图理解... Solution: 找一找规律就可以了,发现方块数为2n*( ...
- 使用idea上传项目到码云
首先,基本流程是这样的: 1.在码云生成SSH公钥 2.在码云创建项目 3.克隆项目到本地 4.在本地创建项目 5.搭建本地仓库,关联远程仓库 ...
- logstash之OutPut插件
output插件是经过了input,然后过滤结构化数据之后,接下来我们需要借助output传到我们想传到的地方.output相当于一个输出管道. 2.3.1: 将采集数据标准输出到控制台 配置示例: ...
- Http协议:客户端提交数据给服务端和从服务端获得数据,像WebView也是向百度的服务端发出一条Http请求,服务端返回HTML页面,客户端(浏览器)解析后展示出页面
提交数据和获得数据的方式有很多,这里介绍一种,使用HttpURLConnection来向服务器提交数据或者获得数据. 获得数据: //传入网址,获得请求网页数据(XML文件数据或JSON文件数据) p ...
- kafka window安装与配置
一.安装jdk1.8(此处省略) 二.安装zookeeper1. 下载安装包:http://zookeeper.apache.org/releases.html,解压到指定目录(如下) 2. 在系统变 ...
- 2018-5 - 热经 - 北京中地时空数码科技有限公司 - 研发工程师(WEBGIS 方向)
一面: 登记,填写个人信息 笔试 选择题: HTML,CSS,JS 的选择题,都是基础题.其中有一道问哪个不是 document 的属性或方法,我在 bgColor 和 focus() 上面纠结了一下 ...
- lua源码学习篇三:赋值表达式解析的流程
上节说到表达式的解析问题,exprstate函数用于解析普通的赋值表达式.lua语言支持多变量赋值.本文先从单变量赋值表达式讲起. a = b = c = a + b 对于简单的两个数的求和过程,lu ...
- Openstack_单元测试工具 tox
目录 目录 扩展阅读 Openstack 的单元测试工具 单元测试工具使用流程 tox toxini 参考文章 扩展阅读 Python Mock的入门 Openstack 的单元测试工具 unitte ...
- Linux监控命令之==>top
一.命令说明 top 命令能够实时监控系统的运行状态,并且可以按照CPU.内存和执行时间进行排序,同时top 命令还可以通过交互式命令进行设定显示,通过top 命令可以查看即时活跃的进行. 二.参数说 ...