1. 程式人生 > >213 Message Decoding

213 Message Decoding

Download as PDF

Some message encoding schemes require that an encoded message be sent in two parts. The first part, called the header, contains the characters of the message. The second part contains a pattern that represents the message. You must write a program that can decode messages under such a scheme.

The heart of the encoding scheme for your program is a sequence of ``key" strings of 0's and 1's as follows:

displaymath26

The first key in the sequence is of length 1, the next 3 are of length 2, the next 7 of length 3, the next 15 of length 4, etc. If two adjacent keys have the same length, the second can be obtained from the first by adding 1 (base 2). Notice that there are no keys in the sequence that consist only of 1's.

The keys are mapped to the characters in the header in order. That is, the first key (0) is mapped to the first character in the header, the second key (00) to the second character in the header, thekth key is mapped to thekth character in the header. For example, suppose the header is:

AB#TANCnrtXc

Then 0 is mapped to A, 00 to B, 01 to #, 10 to T, 000 to A, ..., 110 to X, and 0000 to c.

The encoded message contains only 0's and 1's and possibly carriage returns, which are to be ignored. The message is divided into segments. The first 3 digits of a segment give the binary representation of the length of the keys in the segment. For example, if the first 3 digits are 010, then the remainder of the segment consists of keys of length 2 (00, 01, or 10). The end of the segment is a string of 1's which is the same length as the length of the keys in the segment. So a segment of keys of length 2 is terminated by 11. The entire encoded message is terminated by 000 (which would signify a segment in which the keys have length 0). The message is decoded by translating the keys in the segments one-at-a-time into the header characters to which they have been mapped.

Input

The input file contains several data sets. Each data set consists of a header, which is on a single line by itself, and a message, which may extend over several lines. The length of the header is limited only by the fact that key strings have a maximum length of 7 (111 in binary). If there are multiple copies of a character in a header, then several keys will map to that character. The encoded message contains only 0's and 1's, and it is a legitimate encoding according to the described scheme. That is, the message segments begin with the 3-digit length sequence and end with the appropriate sequence of 1's. The keys in any given segment are all of the same length, and they all correspond to characters in the header. The message is terminated by 000.

Carriage returns may appear anywhere within the message part. They arenotto be considered as part of the message.

For each data set, your program must write its decoded message on a separate line. There should not be blank lines between messages.

TNM AEIOU
0010101100011
1010001001110110011
11000
$#**\
0100000101101100011100101000
TAN ME
##*\$

相關推薦

UVa 213 -- Message Decoding

sci .... ems putchar size ascii碼 () Coding .net Message Decoding simple input TNM AEIOU0010101100011101000100111011001111000 $#**\010

UVa 213 Message Decoding (信息編碼)

== cout HA etc 換行符的處理 ostream flag 回歸 Coding 該題目作為放假回歸正軌的第一道正式做的題目,被卡了好久,唉,怪我有顆太浪的心 解題思路: 1、把編碼頭用二維字符數組存儲起來,a[x][y]存儲對應的字符,x表示編碼的長度,y表示編碼

uvaoj 213 - Message Decoding(二進位制,輸入技巧)

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=149 跨行讀字元的函式readchar()  可以學習一下 把編碼理解成二進位

UVA - 213 Message Decoding

Message Decoding  UVA - 213  題目傳送門 emmmm,此題按照紫書上的思路來即可,要麼太複雜 AC程式碼: #include <cstdio> #include <iostream> #include &

uva 213 Message Decoding 字串處理

Some message encoding schemes require that an encoded message be sent in two parts.  The first part,  called  the  header,  contains  the  characters  of  t

213 Message Decoding

Some message encoding schemes require that an encoded message be sent in two parts. The first part, called the header, contains the characters of the mes

UVa 213 Message Decoding (資訊解碼)

題意: 編寫一個解碼程式,對數字串進行解碼。 輸入第一行是一個解碼key。key從左到右每個字元分別對0,00,01,10,000,001,011,100,101,110,0000,0001,.

UVA-213-Message Decoding 資訊編碼 基礎模擬題 直觀的新手思路+詳細註釋

題意: 1. 首先輸入編碼頭,即一串字串 2. 接下來時只有0和1的串,要求就是對串進行操作然後輸出對應的編碼串 3. 每次編碼先用三個字元計算二進位制和判斷接下來的串時多少個字元為一個編碼 4. 每次編碼遇到全為1的時候結束進行下一次串長判斷(即重複3),直到串長判斷為0

紫書——Message Decoding UVA - 213

題解: 這道題目的精華點就是一開始字元跟二進位制配對的方法。 書本上採用了二維陣列來解決,第1個可以有1個,第2個可以有3個,如此類推,然後之後的就是考你細心程度了,注意getchar和回車的判斷。   書上的程式碼大致如下: #include <iostre

UVA【213Message Decoding

題意:二進位制遍歷問題 每組輸入給一個編碼頭 從頭開始每個字元對應0 00 01 10 000 001 010 011 100 101 110 0000 0001……後面給一串數字 頭三個數表示後面每次讀取的長度 全為1時結束一組輸入 頭三個數為0時編碼結束 輸入樣例:

UVa 213 資訊解碼Message Decoding

不是難題,但卡了我一段時間 看了劉汝佳的書 慢慢的就明白了 主要由對編碼串的處理構成 這部分相信大家看程式碼都能懂 AC程式碼(和書上差不多,但算是一個總結吧) #include <ios

例題 4-4 資訊解碼 (Message Decoding) UVa 213

題意: 給一個編碼頭和一串編碼(編碼可以換行),編碼頭根據以下規則對應編碼{  考慮下面的01串:  0,00,01,10,000,001,010,101,110,0000,0001.....首先是長度為1的串,然後是長度為二的串,以此類推。並且每一段長度的數字從0到(1&

[算法競賽入門經典]Message Decoding,ACM/ICPC World Finals 1991,UVa213

decode 作用 入門 直接 line 所有 字符 for binary Description Some message encoding schemes require that an encoded message be sent in two parts. The

Message Decoding

一、題目大意: 編寫一個解碼程式,對字串進行解碼 解碼規則,根據k,value解碼。 其中k值根據0,00,01,10,000,001,011,100,101,110,0000,0001,…,1101,1110,00000,…序列得到 ,且最大長度不超過7,不存

UVA213 UVALive5152 Message Decoding【密碼】

 Some message encoding schemes require that an encoded message be sent in two parts. The first part, called the header, contains the chara

ActiveMQ(18):Message之延遲和定時消息投遞

jms activemq 延遲和定時消息投遞 一、簡介延遲和定時消息投遞(Delay and Schedule Message Delivery) 有時候我們不希望消息馬上被broker投遞出去,而是想要消息60秒以後發給消費者,或者我們想讓消息沒隔 一定時間投遞一次,一共投遞指定的次數。。。

definition to expand macro then apply to pragma message

pragma macro/* Some test definition here */#define DEFINED_BUT_NO_VALUE#define DEFINED_INT 1#define DEFINED_STR "ABC"/* definition to expand macro then app

ActiveMQ(23):Consumer高級特性之Message dispatche async、Consumer Priority與Message Selectors

jms activemq message dispatche async consumer priority message selectors 一、Message dispatche async(消息異步分發)在activemq4.0以後,你可以選擇broker同步或異步的把消息分發給消

ActiveMQ(22):Consumer高級特性之消息分組(Message Groups)

jms message groups activemq 一、簡介Message Groups就是對消息分組,它是Exclusive Consumer功能的增強。邏輯上,Message Groups 可以看成是一種並發的Exclusive Consumer。跟所有的消息都由唯一的consumer處理

ROS知識(16)----如何編譯時自動鏈接同一個工作空間的其他包的頭文件(包含message,srv,action自動生成的頭文件)

logs package fin 空間 依賴庫 osc div build 知識 catkin_make編譯時,往往需要自動鏈接同一個工作空間的其他包的頭文件。否則會出現類似如下的錯誤: /home/xx/xx_ws/srcA_package/src/db.hpp:13: