#P3982. Binary Code Decryption
Binary Code Decryption
Binary Code Decryption
You are given a string that consists entirely of binary digits (0 and 1). This string is a concatenation of 8-bit units. Each 8-bit unit must be decoded according to the following rules:
- If the first three bits are \(101\), then the unit represents an uppercase letter. The letter is determined by interpreting the last five bits as a binary number, and then mapping \(0\) to
A
, \(1\) toB
, and so on up to \(25\) which maps toZ
. For example, the binary code forA
is10100000
and forC
is10100010
. - If the first three bits are \(111\), then the unit represents a space character.
- If the first bit is \(0\), then the unit represents a number. Note: In this case this unit must be paired with the very next 8-bit unit, which also must start with \(0\). To decode the pair, first convert each unit from binary to decimal, then perform integer division by 2 (i.e. divide by 2 and discard the remainder), and finally add these two results together. The sum (in decimal) is the translation of that pair.
If any 8-bit unit does not follow one of the above rules, the entire input is considered invalid and the output should be exactly Error
.
Input Format: A single line containing a string of binary characters. Its length is guaranteed to be a multiple of 8 if the code is valid.
Output Format: If the code is valid, output its translated message; otherwise, output Error
.
inputFormat
A single line containing a string of binary digits. The string is a multiple of eight characters long.
outputFormat
Output the decoded message according to the rules. If any part of the code is invalid, output Error
.
sample
10100000
A