1. 程式人生 > >uva 213 Message Decoding 字串處理

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  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: 


             0, 00, 01, 10, 000, 001, 010, 011, 100, 101, 110, 0000, 0001, . . . , 1011, 1110, 00000, . . . 


    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, the  kth 
key is mapped to the kth 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 are  not to be considered as 
part of the message. 


Output 


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


Sample input 


TNM   AEIOU 
0010101100011 
1010001001110110011 
11000 
$#**\ 
0100000101101100011100101000 


Sample output 


TAN   ME 

相關推薦

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

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表示編碼

UVA - 213 Message Decoding

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

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

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

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

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

紫書——Message Decoding UVA - 213

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

UVA213Message 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&

UVa:1610 Party Games(字串處理

題意: 給出n個串(n為偶數); 要構造一個串,使n串中有一半小於等於它,另外一半大於它; 要求這個串長度儘量小,同時字典序小 思路1:得益於string自帶字典序比較,所以先對整個字串組排序,那麼中間兩個a,b,答案就要滿足大於等於a,小於b,因為有些細節問題的存在,所以直接暴力列舉就行了

[算法競賽入門經典]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

字串處理演算法(六)求2個字串最長公共部分

基礎演算法連結快速通道,不斷更新中: 整型陣列處理演算法部分: 整型陣列處理演算法(一)按照正態分佈來排列整型陣列元素 整型陣列處理演算法(二)檔案中有一組整數,要求排序後輸出到另一個檔案中 整型陣列處理演算法(三)把一個數組裡的所有元素,插入到另一個數組的指定位置 整型陣列

mysql進行字串處理

mysql進行字串的處理 MySQL 字串擷取函式:left(), right(), substring(), substring_index()。還有 mid(), substr()。其中,mid(), substr() 等價於 substring() 函式,substring()

C++筆試題 字串處理

字串處理 描述 定義字串的以下幾種操作: • reverse(A)獲得A字串的逆序字串,例如reverse(“abc”) = “cba” • shuffle(A)獲得A隨機重排的字串,例如shuffle(“dog”) ∈ {“dog”, “dgo”, “odg”, “ogd”,

字串處理-Hdu1004

題目連結:http://acm.hdu.edu.cn/showproblem.php?pid=1004 題目大意:給你一個數n,要求輸入n個字串,在這n個字串中,我們需要輸出出現次數最多的字串。 這道題看起來的確很簡單,但是卻花了我不少時間,開始時是利用C語言中的char陣列來存這些字串,依次統計,但是做

【C語言】字串處理自定義函式

1、字串求長度 #include <stdio.h> int Mystrlen1(const char *str) { int i=0; while(*(str++)!='\0') { i++; } return i; } int Mystrlen2(cons

E - String of CCPC (字串處理)(str.substr()的運用)

滴答滴答---題目連結  BaoBao has just found a string  of length  consisting of 'C' and 'P' in his pocket. As a big fan of the China