UVA213 Information decoding

Source: Internet
Author: User

In the fourth chapter of the algorithm competition primer, the topic of function and recursion, the application of custom function and binary related content are investigated. (Individuals think that the study of binary related knowledge accounted for more).

Test instructions: To a knitting dock and a string of code (code can be wrapped), the encoding header according to the following rules corresponding encoding {consider the following 01 strings: 0,00,01,10,000,001,010,101,110,0000,0001 ... first is a string of length 1, then a string of length two And so on And each length of the number from 0 to (1<<n)-1 (nth) arrangement, that is, the title does not include all 1 strings.

The encoded text consists of several subsections, the first three digits of each bar representing the length of each encoding in the subsection (example 010 for the encoding length of 2), followed by the encoding of each character, ending with a full 1 bar. Example the first subsection: 00101.

Your task is to write a decoding program that converts the input encoding into a sentence output corresponding to the characters in the encoded header.

Another: Putchar (character ASCII) output character.


#include <bits/stdc++.h>using namespacestd;intcode[8][1<<8];intReadchar () {//reading encoded strings across rows     while(1){        intCh=GetChar (); if(ch!='\ r'&&ch!='\ n')            returnch; }}intReadintintLen) {//reading the encoded string and converting it to a decimal number    intv=0;  while(len--) v=v*2+readchar ()-'0'; returnv;}intReadcode () {//read the encoder header and correspond to the code arraymemset (Code,0,sizeof(code)); code[1][0]=Readchar ();  for(intlen=2; len<=7; len++)         for(intI=0;i< (1<<len)-1; i++) {//not every bit is 1, (1<<len)-1. Note the position of parentheses.             intCh=GetChar (); if(ch==eof)return 0; if(ch=='\ n'|| ch=='\ r')return 1; Code[len][i]=ch; }    return 1;//read to EOF return 0, end input, otherwise return 1 continue to enter the encoding. }intMain () { while(Readcode ()) { while(1){            intLen=readint (3); if(len==0) Break;  while(1){                intv=Readint (len); if(v== (1<<len)-1) Break;            Putchar (Code[len][v]); }} putchar ('\ n'); }    return 0;}

UVA213 Information decoding

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.