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. 使用阿里云主机离线部署CDH步骤详解

    一.Linux文件系统准备 1. 拍摄快照 登录阿里云控制台,拍摄快照,注意有几个关键点尽量拍摄快照,系统初始状态.CM环境准备完成.CM安装完成.CDH安装完成. 2. 挂载设备 三个主机都执行. ...

  2. Linux PCI/PCI-E设备配置空间读取与修改

    Linux PCI/PCI-E设备配置空间读取与修改 1 前言 PCI和PCI Express,是计算机常使用的一种高速总线.操作系统中的PCI/PCI-E设备驱动以及操作系统内核,都需要访问PCI及 ...

  3. 玩转FFmpeg的7个小技巧

    FFmpeg堪称音频和视频应用程序的瑞士军刀,提供了丰富的选项和灵活性.很多时候用户为了看视频和听音乐都安装了ffmeg.更多关于ffmeg的详细介绍:here,可以通过ffmpeg -formats ...

  4. 项目总结1——excel导出相关问题

    1.excel导出文件时,文件名中中文部分空白不显示的问题,原本写法是: String fileName = "物联网PBOSS主机巡检日报-" + inspectTime + & ...

  5. 如何构造一个简单的USB过滤驱动程序

    本文分三部分来介绍如何构造一个简单的USB过滤驱动程序,包括"基本原理"."程序的实现"."使用INF安装".此文的目的在于希望读者了解基本 ...

  6. FusionCharts封装-Value

    Data.java: /** * @Title:Data.java * @Package:com.fusionchart.model * @Description:FusionCharts 封装dat ...

  7. Android常见漏洞

    Android常见漏洞 漏洞名称: Log敏感信息泄露 漏洞描述: 程序运行期间打印了用户的敏感信息,造成泄露 修改建议: 建议禁止隐私信息的log 漏洞名称: web https校验错误忽略漏洞 漏 ...

  8. R语言自动化报告格式——knitr

    R语言自动化报告格式--knitr 相关文献: R语言自动化报告格式--knitr 资讯 | R Notebooks 即将发布 ------------------------------------ ...

  9. 部署Java Web项目报错(一)

    今天,我在部署Java Web项目时,出现错误,并且在eclipse新建一个servers,却出现多个项目. 具体错误截图如下: 然后,我又将项目部署到JBoss服务器中,却还是运行不成功 22:12 ...

  10. jquery Dialog弹框插件使用

    var dialog = new Dialog({ title: '购物车', type: 'url', width: 520, content: "Uplolo.aspx", s ...