POJ2503:Babelfish
浅谈\(Trie\):https://www.cnblogs.com/AKMer/p/10444829.html
题目传送门:http://poj.org/problem?id=2503
\(Trie\)树模板题,就是要你实现一个字典查找的功能。读入十分的恶心。
时间复杂度:\(O(len*n)\)
空间复杂度:\(O(len)\)
代码如下:
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn=1e5+5;
char s[maxn<<1],s1[maxn],s2[maxn];
struct Trie {
int tot;
char s[maxn*10][15];
int son[maxn*10][26];
void ins() {
int pos=1,len=strlen(s2+1);
for(int i=1;i<=len;i++) {
if(son[pos][s2[i]-'a'])pos=son[pos][s2[i]-'a'];
else pos=son[pos][s2[i]-'a']=++tot;
}
len=strlen(s1+1);
for(int i=1;i<=len;i++)
s[pos][i]=s1[i];
}
void find() {
int pos=1,len=strlen(s1+1);
for(int i=1;i<=len;i++) {
if(son[pos][s1[i]-'a'])pos=son[pos][s1[i]-'a'];
else {puts("eh");return;}
}
if(!strlen(s[pos]+1))puts("eh");
else printf("%s\n",s[pos]+1);
}
}T;
int main() {
T.tot=1;
while(1) {
int n,pos;
scanf("%[^\n]",s+1);getchar();
if((n=strlen(s+1))==0)break;
for(int i=1;i<=n;i++)
if(s[i]==' ') {pos=i;break;}
for(int i=1;i<pos;i++)s1[i]=s[i];
for(int i=pos+1;i<=n;i++)s2[i-pos]=s[i];
T.ins(),memset(s,0,(n+1)*4);
}
while(~scanf("%s",s1+1))T.find();
return 0;
}
POJ2503:Babelfish的更多相关文章
- Poj 2503 / OpenJudge 2503 Babelfish
1.Link: http://poj.org/problem?id=2503 http://bailian.openjudge.cn/practice/2503/ 2.Content: Babelfi ...
- java web 开发三剑客 -------电子书
Internet,人们通常称为因特网,是当今世界上覆盖面最大和应用最广泛的网络.根据英语构词法,Internet是Inter + net,Inter-作为前缀在英语中表示“在一起,交互”,由此可知In ...
- 所有selenium相关的库
通过爬虫 获取 官方文档库 如果想获取 相应的库 修改对应配置即可 代码如下 from urllib.parse import urljoin import requests from lxml im ...
- POJ2503——Babelfish(map映射+string字符串)
Babelfish DescriptionYou have just moved from Waterloo to a big city. The people here speak an incom ...
- Babelfish 分类: 哈希 2015-08-04 09:25 2人阅读 评论(0) 收藏
Babelfish Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 36398 Accepted: 15554 Descripti ...
- POJ2503——Babelfish
Description You have just moved from Waterloo to a big city. The people here speak an incomprehensib ...
- POJ2503 Babelfish
题目链接. 分析: 应当用字典树,但stl的map做很简单. #include <iostream> #include <cstdio> #include <cstdli ...
- 题解报告:poj 2503 Babelfish(map)
Description You have just moved from Waterloo to a big city. The people here speak an incomprehensib ...
- POJ2503 Babelfish map或者hash_map
POJ2503 这是一道水题,用Map轻松AC. 不过,可以拿来测一下字符串散列, 毕竟,很多情况下map无法解决的映射问题需要用到字符串散列. 自己生成一个质数, 随便搞一下. #include&l ...
随机推荐
- Log4j详细设置说明
1. 动态的改变记录级别和策略,即修改log4j.properties,不需要重启Web应用,这需要在web.xml中设置一下.2. 把log文件定在 /WEB-INF/logs/ 而不需要写绝对路径 ...
- python 黑客书籍 ——扫描+暴力破解
https://legacy.gitbook.com/book/germey/net-security/details 网络安全 介绍 构建一个端口扫描器 利用Pexpect模拟SSH连接 利用Pxs ...
- Mycat跨分片Join
1 前言 Mycat目前版本支持跨分片的join,主要实现的方式有四种. 全局表 ER分片 HBT(参考MyCAT人工智能解决跨分片SQL.docx) ShareJoin ShareJoin在开发版中 ...
- 005PHP基础知识——数据类型(二)
<?php /** * 布尔型判断一种状态是否成立. * 布尔型 TRUE FALSE * 为布尔假型的类型: * 1. FALSE * 2. 0 * 3. 0.0 * 4. 空字符串为假 * ...
- 十三、dbms_flashback(用于激活或禁止会话的flashback特征)
1.概述 作用:用于激活或禁止会话的flashback特征,为了使得普通用户可以使用该包,必须要将执行该包的权限授予这些用户,grant execute on dbms_flashback to sc ...
- 使用LeakCanary进行内存泄漏追踪
LeakCanary使用 1.在build.gradle 中 dependencies { //添加 debugCompile 'com.squareup.leakcanary:lea ...
- 在pycharm中自定义模板代码,快速输出固定代码块
pycharm中有时会经常输出固定一段代码,为避免每次重复输入,可以自定义一段模板代码,请看以下图教程: 1. 点击 file 里面的 setting 2. 在搜索框输入live,就会显示出 ...
- Python中注释的添加
1.Python中注释,有助于我们对程序的理解:但注释不需要每行都写,可以在方法前面注释该方法的功能 或重要的一行进行注释. 2.单行注释,使用#号: 3.多行注释,使用""&qu ...
- Eclipse上安装springsource-tool-suite
spring tool suite 是一个基于eclipseIDE开发环境中的用于开发spring应用程序的工具.提供了开箱即用的环境用于实现,调试和部署你的spring应用,包括为关键的的服务器和云 ...
- EasyDarwin如何支持点播和RTMP/HLS直播?EasyDSS!
2017年很长很长一段时间没有更新EasyDarwin开源项目了,虽然心里有很多EasyDarwin功能扩展的计划:比如同步录像.同步RTMP/HLS直播输出.拉模式转发优化.Onvif接入.GB28 ...