UVA 644 Immediate decodability (character processing)

Source: Internet
Author: User

An encoding of a set of symbols are said to being immediately decodable if no code for one symbol is the prefix of a code for another symbol. We'll assume for this problem-all codes is in binary, that's no codes within a set of codes is the same, that E The ACH code have at least one bit and no more than ten bits, and so each set have at least, codes and no more than eight.


Examples: Assume an alphabet as has symbols {A, B, C, D}


The following code is immediately decodable:


A:01 B:10 C:0010 D:0000


It's not:


A:01 B:10 C:010 D:0000(Note that a is a prefix of C)

InputWrite A program this 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 was followed by a single separator The record containing a single 9; The separator records is not part of the group. Each group was independent of other groups; The codes in one group was not related to codes with any other group (so is, each group was to be processed independently).

Outputfor each group, your program should determine whether the codes in that group is immediately decodable, and should PR int a single output line giving the group number and stating whether the group are, or is not, immediately decodable.


The Sample Input describes the examples above.

Sample Input

0110001000009011001000009

Sample Output
Set 1 is immediately decodableset 2 are not immediately decodable

A string cannot be a prefix that has a string.

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <map >typedef Long long ll;using namespace std; #define REPF (I, A, b) for (int i = A; I <= B; + + i) #define REP (i , n) for (int i = 0; i < n; + + i) #define CLEAR (A, X) memset (A, x, sizeof a)//map<string,int>q;char s     Tr[1100][10],s[10];int Main () {int cas=1;     Std::ios::sync_with_stdio (FALSE);         while (Cin>>str[0]) {int l=1;         Char *p;         while (cin>>str[l]&&str[l++][0]!= ' 9 ');         int flag=1;                 Rep (I,l-1) {rep (j,l-1) {if (i==j) continue;                 P=strstr (Str[i],str[j]);                     if ((p-str[i)) ==0) {flag=0;                 Break         }}} if (flag) printf ("Set%d is immediately decodable\n", cas++); else printf ("Set%d is not immediately DecOdable\n ", cas++); } return 0;}


Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.

UVA 644 Immediate decodability (character processing)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.