#C1287. Decode Encoded Message
Decode Encoded Message
Decode Encoded Message
You are given an encoded message consisting of alternating letters and digits. Each letter is immediately followed by a single digit, representing how many times that letter should appear in the decoded message.
The encoded string must follow the pattern:
[ S = L_1D_1L_2D_2\ldots L_kD_k ]
where each \(L_i\) is an alphabet character (a-z or A-Z) and each \(D_i\) is a single digit (0-9). The string is considered invalid if:
- The string is empty.
- The string length is odd.
- A letter is not immediately followed by a digit.
If the input is invalid, output Invalid Input
. Otherwise, expand each letter by the number of times indicated by the following digit.
Examples:
- Input:
a3b4c2
→ Output:aaabbbbcc
- Input:
x1y1
→ Output:xy
- Input:
a2b
→ Output:Invalid Input
inputFormat
The input is read from stdin and consists of a single line string representing the encoded message.
outputFormat
The output should be written to stdout as a single line. It is either the decoded message or the string Invalid Input
if the input format is incorrect.
a3b4c2
aaabbbbcc