Description

An encoding of a set of symbols is said to be immediately decodable if no code for one symbol is the prefix of a code for another symbol. We will assume for this problem that all codes are in binary, that no two codes within a set of codes are the same, that each code has at least one bit and no more than ten bits, and that each set has at least two codes and no more than eight.

Examples: Assume an alphabet that has symbols {A, B, C, D}

The following code is immediately decodable:
A:01 B:10 C:0010 D:0000

but this one is not:
A:01 B:10 C:010 D:0000 (Note that A is a prefix of C)

Input

Write a program that accepts as input a series of groups of records from standard input. Each record in a group contains a collection of zeroes and ones representing a binary code for a different symbol. Each group is followed by a single separator record containing a single 9; the separator records are not part of the group. Each group is independent of other groups; the codes in one group are not related to codes in any other group (that is, each group is to be processed independently).

Output

For each group, your program should determine whether the codes in that group are immediately decodable, and should print a single output line giving the group number and stating whether the group is, or is not, immediately decodable.

Sample Input

01
10
0010
0000
9
01
10
010
0000
9

Sample Output

Set 1 is immediately decodable
Set 2 is not immediately decodable
题目大意:
就是输多组0 1数据,任意一组数据不能成为另一种的前缀;

一组符号的编码是立即可解码的如果没有前缀的代码一个符号代码的另一个象征。我们将假定这个问题,所有的二进制代码,没有两个编码在一组编码是相同的,每个代码至少有一个,不超过十位,每组至少有两个编码和不超过8个。

例子:假设一个字母,符号{ A,B,C,D }

下面的代码是立即可解码

#include<iostream>
#include<string>
#include<cstring>
using namespace std;
int main()
{ string str[10];
int i=0; int y=1,w=0;
while(cin>>str[i])
{ if(str[i]=="9")
{
i=0;
w++;
if(y==1)cout<<"Set "<<w<<" is immediately decodable"<<endl;
else cout<<"Set "<<w<<" is not immediately decodable"<<endl;
y=1; } int len=str[i].length(); //新输入字符长度
for(int j=0;j<i;j++) //没输一组数据都与原来的进行比较
{
int t=0;
int len1=str[j].length(); //已存入数据的字符长度
for(int k=0;k<len&&k<len1;k++) //保证以短的字符串长度为比较界限
{
if(str[i][k]==str[j][k])
{ t++;
} }
if(t==min(len,len1)){y=0;break;} //若等式成立则说明此字符串必为某字符串前缀 }
i++;
} return 0; }

  

												

poj-1056-IMMEDIATE DECODABILITY(字典)的更多相关文章

  1. poj 1056 IMMEDIATE DECODABILITY 字典树

    题目链接:http://poj.org/problem?id=1056 思路: 字典树的简单应用,就是判断当前所有的单词中有木有一个是另一个的前缀,直接套用模板再在Tire定义中加一个bool类型的变 ...

  2. poj 1056 IMMEDIATE DECODABILITY(KMP)

    题目链接:http://poj.org/problem?id=1056 思路分析:检测某字符串是否为另一字符串的前缀,数据很弱,可以使用暴力解法.这里为了练习KMP算法使用了KMP算法. 代码如下: ...

  3. POJ 1056 IMMEDIATE DECODABILITY

    IMMEDIATE DECODABILITY Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9630   Accepted: ...

  4. POJ 1056 IMMEDIATE DECODABILITY 【Trie树】

    <题目链接> 题目大意:给你几段只包含0,1的序列,判断这几段序列中,是否存在至少一段序列是另一段序列的前缀. 解题分析: Trie树水题,只需要在每次插入字符串,并且在Trie树上创建节 ...

  5. POJ 1056 IMMEDIATE DECODABILITY Trie 字符串前缀查找

    POJ1056 给定若干个字符串的集合 判断每个集合中是否有某个字符串是其他某个字符串的前缀 (哈夫曼编码有这个要求) 简单的过一遍Trie就可以了 #include<iostream> ...

  6. POJ 2001 Shortest Prefixes(字典树)

    题目地址:POJ 2001 考察的字典树,利用的是建树时将每个点仅仅要走过就累加.最后从根节点開始遍历,当遍历到仅仅有1次走过的时候,就说明这个地方是最短的独立前缀.然后记录下长度,输出就可以. 代码 ...

  7. 【POJ】1056 IMMEDIATE DECODABILITY

    字典树水题. #include <cstdio> #include <cstring> #include <cstdlib> typedef struct Trie ...

  8. hdu 1305 Immediate Decodability(字典树)

    Immediate Decodability Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/O ...

  9. poj 1204 Word Puzzles(字典树)

    题目链接:http://poj.org/problem?id=1204 思路分析:由于题目数据较弱,使用暴力搜索:对于所有查找的单词建立一棵字典树,在图中的每个坐标,往8个方向搜索查找即可: 需要注意 ...

  10. POJ 2408 - Anagram Groups - [字典树]

    题目链接:http://poj.org/problem?id=2408 World-renowned Prof. A. N. Agram's current research deals with l ...

随机推荐

  1. vxWorks 命令

    1.4.1 任务管理    sp( )            用缺省参数创建一个任务(priority="100" 返回值为任务ID,或错误)(taskSpawn) sps( )  ...

  2. Hi3515支持NFS-ROOT启动

    目前在做Hi3515平台监控项目,前期开发一直使用SDK里推荐的mount nfs方式来调试代码,虽然也算方便,但是我一直觉得用法NFS-ROOT才是最省事的方法,而且最接近最终用户使用环境,因为如果 ...

  3. php simpleXML操作xml的用法

    XML简介 XML是一种流行的半结构化文件格式,以一种类似数据库的格式存储数据.在实际应用中,一些简单的.安全性较低的数据往往使用 XML文件的格式进行存储.这样做的好处一方面可以通过减少与数据库的交 ...

  4. freemarker自定义标签(三)-nested指令

    freemarker自定义标签 1.nested指令 是可选的,可以在<#macro>和</#macro>之间使用在任何位置和任意次数 2.示例说明 <#macro ta ...

  5. linux 安装沙盒virtualenv 、virtualenvwrapper

    1.沙盒安装命令: 最新版本:sudo easy_install virtualenv或者sudo apt-get install virtualenv 指定版本:pip install virtua ...

  6. webpacke踩坑-新手

    1.题叶-webpack入门指南 2.webpack入门系列 3.w3ctech的webpack入门及实践 4.Express结合Webpack的全栈自动刷新 5.webpack 单页面应用实战 6. ...

  7. ThreadPoolExecutor线程池参数设置技巧

    一.ThreadPoolExecutor的重要参数   corePoolSize:核心线程数 核心线程会一直存活,及时没有任务需要执行 当线程数小于核心线程数时,即使有线程空闲,线程池也会优先创建新线 ...

  8. LVS-NAT模式的配置详解

    由于实验室拟态存储的项目需要通过NAT模式来映射NFS服务器已实现负载均衡的目的,通过调研了多种负载均衡机制,笔者最终选择了LVS的NAT模式来实现需求,接下来通过博客来记录一下LVS-NAT模式的配 ...

  9. 【bzoj2151】种树

    Time Limit: 1000ms                     Memory Limit: 128MB Description A城市有一个巨大的圆形广场,为了绿化环境和净化空气,市政府 ...

  10. highcharts使用-拼接数据

    在写后台统计时,使用highcharts 作为数据视图化的工具 PHP端 拼接数据 1 首先分组查询出来数据 2 然后拼接出来想要的数据格式 $c_x ='';foreach ($courierGro ...