poj1056
简单题
#include <iostream>
#include <string>
using namespace std; struct cnode
{
cnode *pzero, *pone;
bool end;
}trie[]; int ncount, t; bool insert(cnode *proot, char *a)
{
if (proot->end)
return false;
if (a[] == '')
{
if (a[] != '\0')
{
if (proot->pone == NULL)
{
ncount++;
proot->pone = trie + ncount;
proot->pone->end = false;
proot->pone->pone = NULL;
proot->pone->pzero = NULL;
}
return insert(proot->pone, a + );
}
proot->end = true;
if (proot->pone == NULL && proot->pzero == NULL)
return true;
return false;
}
if (a[] != '\0')
{
if (proot->pzero == NULL)
{
ncount++;
proot->pzero = trie + ncount;
proot->pzero->end = false;
proot->pzero->pone = NULL;
proot->pzero->pzero = NULL;
}
return insert(proot->pzero, a + );
}
proot->end = true;
if (proot->pone == NULL && proot->pzero == NULL)
return true;
return false;
} void init()
{
char* st;
bool ans; st = "";
ncount = ;
trie[].end = false;
trie[].pzero = NULL;
trie[].pone = NULL;
ans = true;
while (true)
{
st = new char[];
if (!(cin >> st))
exit();
if (st[] == '')
break;
if (ans)
if (!insert(trie, st))
ans = false;
getchar();
}
printf("Set %d is ", t);
if (ans)
printf("immediately decodable\n");
else
printf("not immediately decodable\n");
} int main()
{
//freopen("t.txt", "r", stdin);
t = ;
while (true)
{
t++;
init();
}
return ;
}
poj1056的更多相关文章
- POJ1056 IMMEDIATE DECODABILITY & POJ3630 Phone List
题目来源:http://poj.org/problem?id=1056 http://poj.org/problem?id=3630 两题非常类似,所以在这里一并做了. 1056题目大意: 如果一 ...
- poj1056(字符串判断是否存在一个字符串是另一个字符串的前缀)
题目链接:https://vjudge.net/problem/POJ-1056 题意:给定一个字符串集,判断是否存在一个字符串是另一个字符串的前缀. 思路:和hdoj1671一样,有两种情况: 当前 ...
- poj1056 (Trie入门)寻找字符串前缀
题意:给你一堆字符串,问是否满足对于任意两个字符串a.b,a不是b的前缀 字典树==前缀树==Trie树 trie入门题,只用到了insert和query操作 #include <cstdio& ...
- POJ1056 IMMEDIATE DECODABILITY【数据结构】
题目地址:http://poj.org/problem?id=1056 Description An encoding of a set of symbols is said to be immedi ...
- POJ--1056 IMMEDIATE DECODABILITY && POJ--3630 Phone List(字典树)
题目链接 题目大意 看输入的每个字符串中是否有一个字符串是另一个字符串的前缀 #include<iostream> #include<cstring> #include< ...
- ACM训练计划建议(写给本校acmer,欢迎围观和指正)
ACM训练计划建议 From:freecode# Date:2015/5/20 前言: 老师要我们整理一份训练计划给下一届的学弟学妹们,整理出来了,费了不少笔墨,就也将它放到博客园上供大家参考. 菜 ...
- 【POJ水题完成表】
题目 完成情况 poj1000:A+B problem 完成 poj1002:电话上按键对应着数字.现在给n个电话,求排序.相同的归一类 完成 poj1003:求最小的n让1+1/2+1/3+...+ ...
- ACM训练计划建议(转)
ACM训练计划建议 From:freecode# Date:2015/5/20 前言: 老师要我们整理一份训练计划给下一届的学弟学妹们,整理出来了,费了不少笔墨,就也将它放到博客园上供大家参考. 菜 ...
- POJ 1056 IMMEDIATE DECODABILITY Trie 字符串前缀查找
POJ1056 给定若干个字符串的集合 判断每个集合中是否有某个字符串是其他某个字符串的前缀 (哈夫曼编码有这个要求) 简单的过一遍Trie就可以了 #include<iostream> ...
随机推荐
- Spring点滴七:Spring中依赖注入(Dependency Injection:DI)
Spring机制中主要有两种依赖注入:Constructor-based Dependency Injection(基于构造方法依赖注入) 和 Setter-based Dependency Inje ...
- 如何在Eclipse 中查看(如Objects)的源代码
今天突然想看Objects的源码,结果失败了,总结了一下,贴出来. 一般查看源码的流程: 使用快捷键Ctri+Shit+T出现Open Type的对话框,在里面直接输入类名,回车就行: 在Eclips ...
- 【ZJOI 2018】 历史(lct)
历史 题目描述 九条可怜是一个热爱阅读的女孩子. 这个世界有 $n$ 个城市,这 $n$ 个城市被恰好 $n-1$ 条双向道路联通,即任意两个城市都可以互相到达.同时城市 $1$ 坐落在世界的中心,占 ...
- centos下安装ngnix+php+mysql服务
一.nginx 安装 1.查看yum下nginx版本信息 [root@localhost ~]# yum list | grep nginx 2.手动添加nginx的yum仓库 [root@local ...
- Linux及安全实践三——程序破解
Linux及安全实践三--程序破解 一.基本知识 常用指令机器码 指令 作用 机器码 nop 无作用(no operation) 90 call 调用子程序,子程序以ret结尾 e8 ret 返回程序 ...
- Python word_cloud 部分文档翻译 标签云系列(二)
转载地址:https://zhuanlan.zhihu.com/p/20436581上文末尾提到 Python 下还有一款词云生成器.amueller/word_cloud · GitHub 可以直接 ...
- 特征选择实践---python
作者:城东链接:https://www.zhihu.com/question/28641663/answer/110165221来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明 ...
- Pymongo--极简使用指南
1.简介及安装 pymongo是Python中用来操作MongoDB的一个库.而MongoDB是一个基于分布式文件存储的数据库,旨在为WEB应用提供可扩展的高性能数据存储解决方案.其文件存储格式类似于 ...
- (转)tomcat+nginx+redis实现均衡负载、session共享(一)
在项目运营时,我们都会遇到一个问题,项目需要更新时,我们可能需先暂时关闭下服务器来更新.但这可能会出现一些状况: 1.用户还在操作,被强迫终止了(我们可以看日志等没人操作的时候更新,但总可能会有万一) ...
- ElastAlert监控日志告警Web攻击行为
由于公司需要监控web攻击行为,而因某些原因搭不了waf,才不得不用ElastAlert进行告警,此为前提. 一.ELK安装 Elasticsearch 是一个分布式.可扩展.实时的搜索与数据分析引擎 ...