#ACSL2223S2. ACSL2223S2

ACSL2223S2

PROBLEM: Given a string of characters found on the keyboard, convert each character in the string to the binary equivalent of its ASCII code. In the resulting concatenated string, search for the increasing sequence of binary numbers starting with 0, 1, 10, 11, ... until a number cannot befound anywhere in the string. Look from the start of the string. If the binary number is found, remove that occurrence of the binary number from the string. Then look from the end of thestring. If the binary number is found, remove that occurrence of the binary number from the string. Once a number in the sequence cannot be found, convert the string to an octal number without leading Os. Then repeat this same process with a sequence of base 8 numbers 0, ..., 7,10, 11, .... Output the last octal number, converted to base 10, that can successfully be found. If 0 cannot be found, output -1.

EXAMPLE: For the string “Roses are red.”, convert it to a concatenated string of binary numbers using each character’s ASCII code as follows. image image

After removing 100 from both ends as shown above, the process continues until the final string becomes: 0000110000011000010010010000000001000100

The string 1101 cannot be found in this final string. The binary numbers 0, 1, 10, 11, 100, 101, 110, 111, 1000, 1001, 1010, 1011, and 1100 were found and deleted from one or both sides of thestring, but not 1101. The resulting string converted to an octal number is 603022200104. Repeating the same processthe sequence of strings is 603022200104,6302220014,630222004,6302004.602004,60200 sothe last octal number that can be found is 4 since 5 cannot be found in the string.

INPUT: A string containing any character that can be found on the keyboard. The string will befewer than 200 characters.

OUTPUT: Once a number in the sequence cannot be found, output the last octal number.converted to base 10, that can be found in the string after handling all deletions as explainedabove. If 0 cannot be found, output -1.

SAMPLE INPUT:

Roses are red.
A is for Alpha; B is for Bravo; C is for Charlie.
A stitch in time saves nine.
1, 2: Buckle my shoe! 3, 4: Shut the door!
The quick brown fox jumped over the lazy dogs.

SAMPLE OUTPUT:

4
9
8
6
5