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 a data file. 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.

The Sample Input describes the examples above.

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

一个串不能是还有一个串的前缀。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
typedef long long LL;
using namespace std;
#define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )
#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )
#define CLEAR( a , x ) memset ( a , x , sizeof a )
//map<string,int>q;
char str[1100][10],s[10];
int main()
{
int cas=1;
std::ios::sync_with_stdio(false);
while(cin>>str[0])
{
int l=1;
char *p;
while(cin>>str[l]&&str[l++][0]!='9');
int flag=1;
REP(i,l-1)
{
REP(j,l-1)
{
if(i==j) continue;
p=strstr(str[i],str[j]);
if((p-str[i])==0)
{
flag=0;
break;
}
}
}
if(flag) printf("Set %d is immediately decodable\n",cas++);
else printf("Set %d is not immediately decodable\n",cas++);
}
return 0;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

UVA 644 Immediate Decodability (字符处理)的更多相关文章

  1. UVa 644 Immediate Decodability

    吐槽下我的渣渣英语啊,即使叫谷歌翻译也没有看懂,最后还是自己读了好几遍题才读懂. 题目大意:题意很简单,就是给一些互不相同的由'0','1'组成的字符串,看看有没有一个字符串是否会成为另一个的开头的子 ...

  2. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

  3. Volume 1. String(uva)

    10361 - Automatic Poetry #include <iostream> #include <string> #include <cstdio> # ...

  4. 刘汝佳 算法竞赛-入门经典 第二部分 算法篇 第五章 1(String)

    第一题:401 - Palindromes UVA : http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8 ...

  5. umask计算创建文件、目录的默认权限

    很多人以为 创建文件默认权限就是 666-umask=创建文件的默认权限 创建目录的默认权限就是 777-umask=创建目录的默认权限   这种计算其实是不严谨的 为什么我们创建的文件的权限是 64 ...

  6. UVA大模拟代码(白书训练计划1)UVA 401,10010,10361,537,409,10878,10815,644,10115,424,10106,465,10494

    白书一:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=64609#overview 注意UVA没有PE之类的,如果PE了显示WA. UVA ...

  7. UVA 489 Hangman Judge (字符匹配)

    题意:给一个字符串A,只含小写字符数个.再给一个字符串B,含小写字符数个.规则如下: 1.字符串B从左至右逐个字符遍历,对于每个字符,如果该字符在A中存在,将A中所有该字符删掉,若不存在,则错误次数+ ...

  8. UVa 1103 (利用连通块来判断字符) Ancient Messages

    本题就是灵活运用DFS来求连通块来求解的. 题意: 给出一幅黑白图像,每行相邻的四个点压缩成一个十六进制的字符.然后还有题中图示的6中古老的字符,按字母表顺序输出这些字符的标号. 分析: 首先图像是被 ...

  9. UVA - 213 Message Decoding (输入字符串并对单个字符进行操作的输入输出)

    POINT: 关于表示一个编码:利用code字符数组表示一个编码字符,其中code[len][val]表示长度为len,二进制值为val的字符: 主程序如下: #include <iostrea ...

随机推荐

  1. 配置SecureCRT连接Linux CentOS

    链接地址:http://f.dataguru.cn/thread-144513-1-1.html 环境:Linux:centos5.8虚拟机:VirtualBox本机:windows至于怎么安装Cen ...

  2. [javascript]在浏览器端应用cookie记住用户名

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. shell脚本中每次读取文件的一行

    写法一: #!/bin/bash while read linedo      echo $line     #这里可根据实际用途变化 done < file          #需要读取的文件 ...

  4. c++參数传递

    定义: 形參:指出如今Sub 和Function过程形參表中的变量名.数组名,该过程在被调用前.没有为它们分配内存.其作用是说明自变量的类型和形态以及在过程中的作用.形參能够是除定长字符串变量之外的合 ...

  5. Android - Mac系统Android程序位置

    Mac系统Android程序位置 本文地址: http://blog.csdn.net/caroline_wendy Mac系统是类Unix系统.Android程序直接安装至目录.能够使用" ...

  6. 简单描述RAID级别:

    简单描述RAID级别: RAID 0 是俩盘一起读写,如果一个坏了那么数据全丢失: RAID 1是一块写,一块用来备份,坏一块无所谓: RAID 2 ,3 ,4 不常用: 最常用的就是RAID 5和R ...

  7. HDOJ 2680 Dijkstra

    题目大意: 给你一个有向图,一个起点集合,一个终点,求最短路.... 解题思路: 1.自己多加一个超级源点,把起点集合连接到超级源点上,然后将起点与超级源点的集合的路径长度设为0,这样就称为一个n+1 ...

  8. QPointer更安全,QScopedPointer自动出范围就删除,QSharedDataPointer帮助实现隐式共享

    http://blog.csdn.net/hai200501019/article/details/8474582http://blog.csdn.net/hai200501019/article/d ...

  9. Qt线程QThread简析(8个线程等级,在UI线程里可调用thread->wait()等待线程结束,exit()可直接退出线程,setStackSize设置线程堆栈,首次见到Qt::HANDLE,QThreadData和QThreadPrivate)

    QThread实例代表一个线程,我们可以重新实现QThread::run(),要新建一个线程,我们应该先继承QThread并重新实现run()函数. 需要注意的是: 1.必须在创建QThread对象之 ...

  10. jstl 保留两位小数

    简介:jstl保留两位小数实现方法在JSP开头导入以下标签:<%@tagliburi="http://java.sun.com/jsp/jstl/fmt"pre jstl 保 ...