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算法,恰逢遇到朋友吐槽最近被和谐的词越来越多了,于是突发奇想,想要自己实现一下敏感词屏蔽. 基本敏感词的屏蔽说起来很简单,只要把字符串中的敏感词替换成"* ...
随机推荐
- MySQL5.7数据转移至SQL Server详解
本文链接:https://blog.csdn.net/qq_37308779/article/details/80679358一.安装MySQL ODBC驱动为MySQL安装Connector/ODB ...
- Linux培训教程 linux磁盘分区详解
在学习 Linux 的过程中,安装 Linux 是每一个初学者的第一个门槛.在这个过程中间,最大的困惑莫过于给硬盘进行分区.虽然,现在各种发行版本的 Linux 已经提供了友好的图形交互界面,但是很多 ...
- BZOJ 4769: 超级贞鱼 逆序对 + 归并排序
手画几下序列的变换后发现逆序对数是恒定的,故只需对第 $0$ 年求逆序对即可. 树状数组会 $TLE$ 的很惨,需要用到归并排序来求逆序对. 其实就是省掉了一个离散化的时间,估计能比树状数组快一半的时 ...
- R 去掉非零元素
X <- X[X!=] Malign_score <- Malign_score[Malign_score>=0.0008]
- POJ 1573 Robot Motion(模拟)
题目代号:POJ 1573 题目链接:http://poj.org/problem?id=1573 Language: Default Robot Motion Time Limit: 1000MS ...
- 指定文件或文件夹直接提交到svn指定目录
我这里先说两种方法第一种:1.先将那个目录checkout下来2.将要添加的文件或者文件夹放到这个目录中3.右击文件执行svn菜单中的add命令4.右击文件执行svn菜单中的commit命令第二种:如 ...
- Spring Boot教程(十二)整合elk(1)
elk 简介 Elasticsearch是个开源分布式搜索引擎,它的特点有:分布式,零配置,自动发现,索引自动分片,索引副本机制,restful风格接口,多数据源,自动搜索负载等. Logstash是 ...
- for循环,foreach, map,reduce用法对比+for in,for of
for不做赘述,相当简单: foreach方法: forEach() 方法用于调用数组的每个元素,并将元素传递给回调函数. 注意: forEach() 对于空数组是不会执行回调函数的. array.f ...
- [LeetCode]-DataBase-Customers Who Never Order
Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL qu ...
- spring boot: Whitelabel Error Page的解决方案
http://blog.csdn.net/u014788227/article/details/53670112