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 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的更多相关文章

  1. UVa 644 Immediate Decodability

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

  2. hdu 1305 Immediate Decodability(字典树)

    Immediate Decodability Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/O ...

  3. Immediate Decodability(字典树)

    Immediate Decodability Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/O ...

  4. UVA644 Immediate Decodability

    UVA644 Immediate Decodability Trie Trie模板题 难度几乎相等的题P2580 于是他错误的点名开始了 对于每组数据都清空树太浪费时间,所以我们只要在需要新点时预先把 ...

  5. POJ1056 IMMEDIATE DECODABILITY & POJ3630 Phone List

    题目来源:http://poj.org/problem?id=1056   http://poj.org/problem?id=3630 两题非常类似,所以在这里一并做了. 1056题目大意: 如果一 ...

  6. HDU 1305 Immediate Decodability 可直接解码吗?

    题意:一个码如果是另一个码的前缀,则 is not immediately decodable,不可直接解码,也就是给一串二进制数字给你,你不能对其解码,因解码出来可能有多种情况. 思路:将每个码按长 ...

  7. 「UVA644」 Immediate Decodability(Trie

    题意翻译 本题有多组数据.每组数据给出一列以"9"结尾的仅包含'0'和'1'的字符串,如果里面有一个是另一个的子串,输出"Set &case is not imm ...

  8. POJ 1056 IMMEDIATE DECODABILITY

    IMMEDIATE DECODABILITY Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9630   Accepted: ...

  9. HDU1305 Immediate Decodability (字典树

    Immediate Decodability An encoding of a set of symbols is said to be immediately decodable if no cod ...

  10. hdu 1305 Immediate Decodability

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1305 字典树裸题,如下: #include<algorithm> #include< ...

随机推荐

  1. HDU 3046 Pleasant sheep and big big wolf(最小割)

    HDU 3046 Pleasant sheep and big big wolf 题目链接 题意:一个n * m平面上,1是羊.2是狼,问最少要多少围墙才干把狼所有围住,每有到达羊的路径 思路:有羊和 ...

  2. server宕机监控、检測、报警程序(139绑定手机短信报警)monitor_down.sh

    宕机监控报警程序 一.   需求来源 宕机对运维人员来说,最痛苦了.怎样检測一台server是否还在正常执行,假设该server宕机,怎样在第一时间监測到并通知一线运维人员进行维护,最大化降低损失. ...

  3. android-supporting-multiple-devices

    There are a few common questions asked whenever development begins on a new Android app. What assets ...

  4. java--jsp+ssh+select动态结合数据和选择(解)

    在三层体系结构和jsp合并项目,如何实现select动态绑定数据和动态选择指定的行?让我们来看看下面的: 1.首先定义一个Bean分类.它用于实例select的结合数据中的每一个id和name: pu ...

  5. 使用my97datepicker控件实现日期范围选择

    注:(2014-12-05内容修改:添加运行效果) 使用my97datepicker 控件,需要对日期的范围进行控制,本人自己写了一个js完成此功能,示例为当前日期到下一周周五之间的日期可选,其他日期 ...

  6. Spoken English

    The Business lunch 9.商务午餐怎样开场?[0731] Is this your first time in shanghai? 10.怎样询问对方的感受?[0801] How do ...

  7. IdeasToComeTrue

    灵感这玩意,果真是有的吧.不考虑什么架构和盈利模式,就只是想到的有趣,随便写写,以飨流年. 我的头脑风暴:爱玩儿aiWaner 2015/08/22 换书: 每个人可能有很多闲置图书,自己看完了觉得好 ...

  8. 《Effective C++》Item2:尽量以const,enum,inline替换#define

    1. 宏定义 #define ASPECT_RATIO 1.653 该宏定义ASPECT_RATIO也许从来没有被编译器看到,也许在编译器开始处理源码之前就已经被预处理器替换了.所以记号名称ASPEC ...

  9. hdu 3498 whosyourdaddy 重复覆盖

    题目链接 重复覆盖的入门题, 和精确覆盖不一样, 删除的时候只删除一行多列. #include<bits/stdc++.h> using namespace std; #define pb ...

  10. 写了个小爬虫,为何用上代理ip总是出现错误。

    import urllib.request import re import os import random import threading def url_open(url): #在第8到第12 ...