Immediate Decodability
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 (Note that A is
B:10 C:010 D:0000
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
HINT
//(如果任意一个串,均不是其它串的前缀则表明,is immediately decodable,否则is not immediately decodable)
#include<stdio.h>
#include<string.h>
int main()
{
char a[100][100];
int t=0,i,j,t1,t2,k,s=1;
while(gets(a[t]))
{
t++;
while(gets(a[t]))
{
if(a[t][0]=='9')
break;
t++;
}
for(i=0;i<t;i++)
{
t1=strlen(a[i]);
for(j=i+1;j<t;j++)
{
//t2=strlen(a[j]);
for(k=0;k<t1;k++)
{
if(a[i][k]!=a[j][k])//(is immediately decodable)
break;
}
if(k==t1)//(is not immediately decodable)
break;
}
if(j!=t)//(is not immediately decodable)
break;
}
if(i==t)
printf("Set %d is immediately decodable\n",s);
else
printf("Set %d is not immediately decodable\n",s); //for(i=0;i<t;i++)
//printf("%s\n",a[i]);
//printf("\n");
t=0;
s++;
}
return 0;
}
//参考他人代码
单模式匹配算法:给定一个单词和一个字符串,查看字符串中是否存在该单词,通过调用strstr函数进行匹配;
#include<iostream>
#include<string>
#include<stdio.h>
#include<string.h> using namespace std ; int main()
{
char word[1000][20] ;
int t = 1 ;
while(cin >> word[0])
{
int i = 1 ;
while(cin >> word[i++])
if(strcmp(word[i-1],"9")==0)
break ;
bool flag = true ;
i--;
for(int j = 0 ; j < i ; j++)//每一行均与其它进行比较
{
char *p = NULL ;
for(int k = 0 ; k < i ; k++)
{
if(j == k)
continue ;
p = strstr(word[j],word[k]) ;//第j行在其它行(k)中遍历,看是否是其前缀。
if(p == word[j])
{
flag = false ;
break ;
}
}
if(flag == false)
break ;
}
if(flag)
printf("Set %d is immediately decodable\n",t++) ;
else
printf("Set %d is not immediately decodable\n",t++) ;
}
return 0 ;
}
Immediate Decodability的更多相关文章
- UVa 644 Immediate Decodability
吐槽下我的渣渣英语啊,即使叫谷歌翻译也没有看懂,最后还是自己读了好几遍题才读懂. 题目大意:题意很简单,就是给一些互不相同的由'0','1'组成的字符串,看看有没有一个字符串是否会成为另一个的开头的子 ...
- hdu 1305 Immediate Decodability(字典树)
Immediate Decodability Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/O ...
- Immediate Decodability(字典树)
Immediate Decodability Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/O ...
- UVA644 Immediate Decodability
UVA644 Immediate Decodability Trie Trie模板题 难度几乎相等的题P2580 于是他错误的点名开始了 对于每组数据都清空树太浪费时间,所以我们只要在需要新点时预先把 ...
- POJ1056 IMMEDIATE DECODABILITY & POJ3630 Phone List
题目来源:http://poj.org/problem?id=1056 http://poj.org/problem?id=3630 两题非常类似,所以在这里一并做了. 1056题目大意: 如果一 ...
- HDU 1305 Immediate Decodability 可直接解码吗?
题意:一个码如果是另一个码的前缀,则 is not immediately decodable,不可直接解码,也就是给一串二进制数字给你,你不能对其解码,因解码出来可能有多种情况. 思路:将每个码按长 ...
- 「UVA644」 Immediate Decodability(Trie
题意翻译 本题有多组数据.每组数据给出一列以"9"结尾的仅包含'0'和'1'的字符串,如果里面有一个是另一个的子串,输出"Set &case is not imm ...
- POJ 1056 IMMEDIATE DECODABILITY
IMMEDIATE DECODABILITY Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9630 Accepted: ...
- HDU1305 Immediate Decodability (字典树
Immediate Decodability An encoding of a set of symbols is said to be immediately decodable if no cod ...
- hdu 1305 Immediate Decodability
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1305 字典树裸题,如下: #include<algorithm> #include< ...
随机推荐
- C++箴言:避免构造或析构函数中调用虚函数
如果你已经从另外一种语言如C#或者Java转向了C++,你会觉得,避免在类的构造函数或者析构函数中调用虚函数这一原则有点违背直觉.但是在C++中,违反这个原则会给你带来难以预料的后果和无尽的烦恼. 正 ...
- Android软件版本更新
转的:适合新手学习,但在实际项目中不可这么做. 以下是我转的内容: ================================================================= ...
- csu 1563 Lexicography
题意:给出一堆字母 问这些字母组成的字符串中第k大的 排列组合,具体看代码 //寒假集训被何柱大大踩好惨(>_<) #include<cstdio> #include<i ...
- c#搭建服务端 准备工作(1)
思路 搭建服务器主要为了接收客户端所传来的数据,在学习过程中,整体的搭建逻辑大体分为以下几个步骤: 1.启动线程监听服务端口 2.监听客户端链接并进行处理 3.接收客户端传入的消息 4.向客户端回传( ...
- js原生forEach、map与jquery的each、$.each的区别
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...
- C++ DLL注册
今天项目中需要用C++实现对几个DLL文件的注册,查了许多资料,总结如下: #include <SHLWAPI.H> #pragma region DLL 注册与反注册 add by wh ...
- 前端模块与CMS结合
前端模块与CMS结合 在<FIS官方技术群>经常看到一些讨论,这次是 前端组件化与CMS的相关讨论,主要观点来自群里 漂流瓶(张云龙前辈). CMS是运营人员直接操作,我们往往需求各种各样 ...
- 基于Jquery的Ajax分页,只有上一页和下一页
最近项目中用到ajax分页 在网上找到一个非常好用的分页插件jquery-pagination-ajax,以下是链接 http://www.zhangxinxu.com/wordpress/2010/ ...
- 2014.9.15HTML
<html> <title> </title> ——页面标题 <head> </head> ——网页上的控制信息 <body> ...
- 选项卡 js操作
html代码展示(这里展示的是关于日程的标签页)css样式这里省略了>>>>自己写的可能更好看 <div class="row"> <ul ...