吐槽下我的渣渣英语啊,即使叫谷歌翻译也没有看懂,最后还是自己读了好几遍题才读懂。

题目大意:题意很简单,就是给一些互不相同的由'0','1'组成的字符串,看看有没有一个字符串是否会成为另一个的开头的子串。

直接简单粗暴的去比较就可以了。

这是原题:

  Immediate Decodability 

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

Miguel A. Revilla 
2000-01-17

AC代码:

 //#define LOCAL
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; char code[][];
bool cmp(char s1[], char s2[]); int main(void)
{
#ifdef LOCAL
freopen("644in.txt", "r", stdin);
#endif
int kase = , n;
while(gets(code[]))
{
bool flag = false;
int i, j;
n = ;
while(code[n][] != '')
gets(code[++n]); for(i = ; i < n - ; ++i)
{
if(flag)
break;
for(j = i + ; j < n; ++j)
{
flag = cmp(code[i], code[j]);
if(flag) break;
}
} if(!flag)
printf("Set %d is immediately decodable\n", ++kase);
else
printf("Set %d is not immediately decodable\n", ++kase);
}
return ;
}
//比较一个字符串是否会成为另一个的开头的子串
bool cmp(char s1[], char s2[])
{
int l1 = strlen(s1);
int l2 = strlen(s2);
int lmin = min(l1, l2), i = ;
if(l1 == l2)//长度相等,必然不会是子串
return false;
for(i = ; i < lmin; ++i)
{
if(s1[i] != s2[i])
break;
}
if(i == lmin)
return true;
return false;
}

代码君

UVa 644 Immediate Decodability的更多相关文章

  1. UVA 644 Immediate Decodability (字符处理)

    An encoding of a set of symbols is said to be immediately decodable if no code for one symbol is the ...

  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. 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 ...

  6. UVa 10012 - How Big Is It? 堆球问题 全排列+坐标模拟 数据

    题意:给出几个圆的半径,贴着底下排放在一个长方形里面,求出如何摆放能使长方形底下长度最短. 由于球的个数不会超过8, 所以用全排列一个一个计算底下的长度,然后记录最短就行了. 全排列用next_per ...

  7. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  8. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

  9. UVA 11404 Palindromic Subsequence[DP LCS 打印]

    UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...

随机推荐

  1. Python日志输出——logging模块

    Python日志输出——logging模块 标签: loggingpythonimportmodulelog4j 2012-03-06 00:18 31605人阅读 评论(8) 收藏 举报 分类: P ...

  2. flashdevelop 开发技巧

    FlashDevelop用来编写AS3代码,Flash CS5用来编辑程序所需要的资源(图片,声音-),Flash CS5自带有Flex SDK,在目录 C:\Program Files\Adobe\ ...

  3. 使用 Swagger UI 与 Swashbuckle 创建 RESTful Web API 帮助文件

    作者:Sreekanth Mothukuru 2016年2月18日 本文旨在介绍如何使用常用的 Swagger 和 Swashbuckle 框架创建描述 Restful API 的交互界面,并为 AP ...

  4. F.I.S本地环境的搭建教程

    一.准备开发环境: 1.安装JRE 2.安装nodejs 最好是msi文件,比较省事. 3.(如果是PHP项目)安装php. 首先下载php(我的是5.5.15版本,win7 64位系统) zip,然 ...

  5. [Qt] 界面美化 [2013-06-17更新](转载)

    - 经验总结 1. 可用对话框(QDialog)模拟类似Android中toast的效果.     - 设置程序界面风格 在main函数中QApplication::setStyle("wi ...

  6. SiteView

    http://www.siteview.com/cms/sites/public/home.html

  7. WCF分布式开发步步为赢(4):WCF服务可靠性传输配置与编程开发

    今天继续WCF分布式开发步步为赢系列的第4节:WCF服务可靠性传输配置与编程开发.这个章节,我们要介绍什么是WCF服务的可靠性传输,随便介绍网络协议的概念,Web Service为什么不支持可靠性传出 ...

  8. UVA 10943 How do you add? DP

    Larry is very bad at math — he usually uses a calculator, whichworked well throughout college. Unfor ...

  9. x64 结构体系下的内存寻址

    欢迎转载,转载请注明出处:http://www.cnblogs.com/lanrenxinxin/p/4735027.html 在阅读NewBluePill源码的时候,看内存的那一块简直头疼,全是x6 ...

  10. 矩阵快速幂 POJ 3070 Fibonacci

    题目传送门 /* 矩阵快速幂:求第n项的Fibonacci数,转置矩阵都给出,套个模板就可以了.效率很高啊 */ #include <cstdio> #include <algori ...