Programming contests

DEIK Regionális Programozó Csapatverseny, egyetemi/főiskolai kategória, 2013. december 1.

December 1, 2013 10:30 AM – December 1, 2013 3:30 PM

The Base-1 Number System

As we know, in an n-based number system, there are n different types of digits. In this way, a 1-based number system has only 1 type of digit, the “0”. Here are the rules to interpret 1-based numbers. Each number consists of some space-separated blocks of 0. A block may have 1, 2, or more 0s. There is a flag variable associated with each number.

  • A block with a single 0 sets the flag variable to 1.
  • A block with two 0s sets flag to 0.
  • If there are n (n > 2) 0s in a block, n – 2 binary digits with the current value of flag is appended to your number.

Note that the first block of every number will have at most 2 0s. For example, the 1-based number 0 0000 00 000 0 0000 is equivalent to binary 11011:

  • The 1st block sets flag to 1.
  • The 2nd block has 4 0s, so it appends flag (=1) 4 – 2 = 2 times (11).
  • The 3rd block has 2 0s, it sets flag to 0.
  • The 4th block has 3 0s, it appends flag (=0) 3 – 2 = 1 time (110).
  • The 5th block has has a single 0, it sets flag to 1.
  • The 6th block has 4 0s, it appends flag (=1) 4 – 2 = 2 times (11011).

The final binary number won’t have more than 30 digits. Once you’ve completed the process, convert the binary value to decimal and print it. You’re done!

Input Specification

The input will have at most 100 test cases. Each test case consists of a 1-based number as described above. A number may be spanned to multiple lines, but a single block will always be in a single line. Termination of a case will be indicated by a single “#” character, which will be space-separated from the last digit of your input number. The last case in the input is followed by a “~” character, indicating the end of input.

Output Specification

For each test case, output a single line with the decimal equivalent value of your given 1-based number.

Sample Input

  1. 0 0000 00 000 0 0000 #
  2. 0 000 #
  3. ~
download as text file

Output for Sample Input

  1. 27
  2. 1
download as text file
University of Debrecen; Faculty of Informatics; v. 03/01/2019