P3982 Longpan Snow Peak Information Parser
Background
```cpp
薄雾笼罩,远方的雪峰无限迷人,感慨之间,阴影将至。
```
Longpan Snow Peak, adjacent to the Yuzhencheng Ocean, stays in contact with us. However, the correspondent at Longpan Snow Peak often encrypts messages in strange ways and then asks us to decipher them—very cautious indeed. Over time, our own correspondents grew impatient, nearly flipping tables and smashing stools in frustration. So we want to build an information parser. That’s it.
Description
Messages from Longpan Snow Peak are encrypted into complex codes. We need you to write a program that deciphers these codes according to the rules below and translates them into text.
The code is a continuous string of binary digits (only $ 0 $ and $ 1 $; when adding, carry $ 1 $ whenever it reaches $ 2 $; each $ 0 $ or $ 1 $ occupies one character). Every eight characters form one unit (this is also a rule).
Each unit follows these rules:
1. If the first three characters are $ 101 $, the unit represents a letter $ A\text{-}Z $. The code for $ A $ is $ 10100000 $, the code for $ C $ is $ 10100010 $. The $ 26 $ uppercase letters are arranged in alphabetical order following this pattern, each corresponding to a unique binary code.
2. If the first three characters are $ 111 $, the unit translates to a space.
3. If the first character is $ 0 $, then the unit represents a number to be added to the number represented by the next unit. During this addition, convert these two units to decimal, then divide each by $ 2 $ and discard the remainder before adding. After the addition, the sum is the translation result for these two units (the result is expressed in decimal). Both of these units are then considered fully translated (see Sample $ 3 $).
For safety, Longpan Snow Peak often sends “fake code,” which does not follow the rules above. If fake code appears, only output Error.
Input Format
The input contains a single line with a continuous code string (length does not exceed $ 171111 $ characters). No spaces will appear, and the input is guaranteed to be non-empty.
Output Format
Output a single line containing the string produced by translating the binary code according to the rules above.
If the binary code contains any fake code, only output Error.
Explanation/Hint
Explanation for Sample $ 1 $:
$ 10100000 $ represents $ A $. The next unit begins with $ 111 $, which translates to a space. The next unit begins with $ 101 $ and is followed by $ 01111 $, which is $ 2^0+2^1+2^2+2^3=15 $ more than $ A $, so it represents $ P $. By analogy, the final translation is $ A\;PIG $.
Note:
For Rule $ 1 $: the $ 26 $ uppercase letters are arranged in alphabetical order, starting from $ A=10100000 $. Each subsequent letter’s binary code has a value exactly $ 1 $ greater than the previous letter’s binary code (remember to carry in base $ 2 $).
This problem is prone to misunderstandings. Please read the statement carefully, clarify the logical relationships, and pay attention to details.
Translated by ChatGPT 5