P28247 [洛谷] Dragon Peak Information Decoder
提高-
题目描述

Background

Mist shrouds the distant snow-capped peaks, infinitely charming, yet shadows approach.

The Dragon Peak雪山, adjacent to the Zhencheng Ocean, maintains contact with us. However, the Dragon Peak's communicators often encrypt their messages in strange ways, asking us to decipher them, which is quite cautious. Over time, our communicators have grown impatient, almost ready to flip tables and smash chairs in frustration. Therefore, we want to create an information decoder, and that's what this is about.

Problem Description

The messages from Dragon Peak are encrypted into complex codes. We need you to create a program that decrypts these codes according to the decoding rules and translates them into text messages. Here are the decoding rules:

The code should be a series of binary digits (only consisting of 0 and 1, with a carry-over at 2 during addition, each 0 or 1 occupying one character), with every eight characters forming a unit (this is also a rule).

Each unit follows these rules:
1. If the first three characters are 101, it indicates a letter from A-Z. The letter A is coded as 10100000, and the letter C is 10100010. The 26 uppercase letters are arranged sequentially in the alphabet according to this pattern, each corresponding to a binary code.
2. If the first three characters are 111, the unit translates to a space.
3. If the first character is 0, the unit represents a number, which is to be added to the number represented by the next unit. During addition, these two units should be converted to decimal, then divided by 2 and the remainder discarded before adding. The result of this addition is the translation result for these two units (the translation result is in decimal, and both units are considered translated, see Sample 3 for details).

For safety, Dragon Peak often sends fake codes, which do not follow the above rules. If a fake code is encountered, only output Error.

Input Format

Input consists of a single line containing a continuous string of code (with a length not exceeding 171111 characters), with no spaces in between, and no empty code is guaranteed.

Output Format

Output consists of a single line containing a string, which is the text message translated from the binary code according to the above rules.

If the binary code contains fake code information, only output Error.

Sample Input and Output

Sample Input #1

1010000011100000101011111010100010100110

Sample Output #1

A PIG

Sample Input #2

1

Sample Output #2

Error

Sample Input #3

0000001000000010000000100000001010100000

Sample Output #3

22A

Sample Input #4

IOIOOOOI

Sample Output #4

Error

Notes

Sample 1 Explanation:

10100000 represents A, the next unit starts with 111, which translates to a space, and the next unit starts with 101, followed by 01111, which is 15 more than A, representing P, and so on, resulting in A PIG.

Attention:

For the explanation of Rule 1: The 26 uppercase letters are arranged in alphabetical order, starting with A=10100000, with each subsequent letter's binary code value being 1 more than the previous one (note the carry-over at 2);

This problem has been misunderstood, so please read the problem carefully, understand the logical relationships, and pay attention to details!

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
1010000011100000101011111010100010100110
样例输出
A PIG