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

题目大意:题意很简单,就是给一些互不相同的由'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. SSH无密码验证

    一.安装和启动SSH协议 sudo yum install ssh sudo yum install rsync service sshd restart 启动服务 (rsync是一个远程数据同步工具 ...

  2. jquery 插件开发及extend

    以下信息是在看了IBM上的一篇文章(使用 jQuery(中级),第 2 部分: 创建自己的插件)http://www.ibm.com/developerworks/cn/web/wa-aj-jquer ...

  3. SEO网站优化方案

    学习许多前辈的经验,看到一些比较有价值的seo优化方案,特记录一下,对照自己的操作之路,新人也可借鉴一二,下面是从卢松松博客看到的文章.高手直接跳过,请勿喷水. 一个完整的SEO优化方案主要由四个小组 ...

  4. jxl.dll操作总结

    1)Jxl是一个开源的Java Excel API项目,通过Jxl,Java可以很方便的操作微软的Excel文档.除了Jxl之外,还有Apache的一个POI项目,也可以操作Excel,两者相比之下: ...

  5. POJ 1940

    #include <iostream> #include <iomanip> #define MAXN 1000 using namespace std; struct nod ...

  6. Android调用天气预报的WebService简单例子

    下面例子改自网上例子:http://express.ruanko.com/ruanko-express_34/technologyexchange5.html 不过网上这个例子有些没有说明,有些情况不 ...

  7. 构建iOS稳定应用架构时方案选择的思考,主要涉及工程结构,数据流思想和代码规范

    工程结构架构,减少耦合混乱以及防治需求大改造成结构重构,如何构建稳定可扩展可变换的工程结构的思考 我打算采用Information flow的方式自上而下,两大层分为基础层和展现层的结构.基础层分为多 ...

  8. (11)nehe教程5---3D空间

    3D空间: 我们使用多边形和四边形创建3D物体,在这一课里,我们把三角形变为立体的金子塔形状,把四边形变为立方体. 在上节课的内容上作些扩展,我们现在开始生成真正的3D对象,而不是象前两节课中那样3D ...

  9. VS输入法问题

    问题描述:启动VS,打开Winform等的界面设计,无法为控件输入中文,另外,运行程序,无法在TextBox等控件中输入中文: 本人的系统环境:Win7旗舰版,VS2008.VS2010和VS2012 ...

  10. 李洪强iOS开发之- 实现简单的弹窗

     李洪强iOS开发之- 实现简单的弹窗 实现的效果:  112222222222223333333333333333