Immediate Decodability
来源:互联网 发布:上海兄弟连java学费 编辑:程序博客网 时间:2024/06/08 18:23
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
0110001000009011001000009
Sample Output
Set 1 is immediately decodableSet 2 is not immediately decodable
大意:
给一组数据以9结束,判断这组数据中的某一行是否是另外一行的前缀
要点:
接受到的STRING字符串要先排序 才能比较
代码:
#include <iostream>#include <string>using namespace std;string text[10];string t;int mycount = 1;void mysort(int n){for (int i = 0; i < n; i++){string min = text[i];for (int j = i + 1; j < n; j++){if (text[j] < min){min = text[j];text[j] = text[i];text[i] = min;}}}}void match(int n){for (int i = 0; i < n - 1; i++){for (int j = i + 1; j < n; j++){int leng = text[i].length();t = text[j].substr(0, leng);if (text[i] == t){cout << "Set " << mycount << " is not immediately decodable" << endl;mycount++;return;}}}cout << "Set " << mycount << " is immediately decodable" << endl;mycount++;return;}int main(){int num = 0;while (cin >> text[num]){if (text[num] == "9"){mysort(num);match(num);for (int i = 0; i < 10; i++)text[num] = "";num = -1;}num++;}}
- Immediate Decodability
- Immediate Decodability
- Immediate Decodability
- Immediate Decodability
- Immediate Decodability
- Immediate Decodability
- IMMEDIATE DECODABILITY
- Immediate Decodability
- Immediate Decodability
- fjnu 1112 IMMEDIATE DECODABILITY
- 1056 IMMEDIATE DECODABILITY
- 644--Immediate Decodability
- 1056 IMMEDIATE DECODABILITY //trie
- poj 1056 : immediate decodability
- POJ 1056 IMMEDIATE DECODABILITY
- HDOJ Immediate Decodability
- uva 644 Immediate Decodability
- UVa 644 - Immediate Decodability
- windows下关于nodejs和npm的安装、方法,网址
- [容器-OpenStack] 一键部署OpenStack
- 3.2 Qemu Memory管理
- mysql 锁
- C++ 深入了解 函数, 虚函数, 单继承,多继承,指针,引用。
- Immediate Decodability
- 3.3EPT内存虚拟化
- 并查集应用食物链poj1182
- 打鱼还是晒网
- 通过函数回调排序结构体数组
- LeetCode---(197)Largest Number
- 3.4Shadowpage页表虚拟化
- J2ee入门之开发环境搭建
- POJ 1436 Horizontally Visible Segments(线段树区间染色问题)