LCC/Moose '19 Contest 4 S2 - Tape Editor

View as PDF

Submit solution

Points: 5 (partial)
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type

Alan and Alonzo recently came across an old computer at a garage sale which can be used as a text editor. The computer has a seemingly endless tape that stores characters which the user can manipulate by either changing the character at the current tape position or by changing the tape position.

Alan is really excited about this computer and claims that it’s just as powerful as any other computer, but Alonzo doesn’t think it’s a big deal. To show Alan that the computer is simple, Alonzo would like to write a program to simulate it. Can you help Alonzo achieve this goal?

Specifically, suppose that the computer starts out with the tape being blank and the tape position being at the leftmost end of the tape. Given a set of instructions, output the non-blank positions contained on the tape after those instructions are executed.

Input Specification

The input begins with a single integer N (1 \le N \le 100), the number of instructions to execute.The next N lines each contain a single instruction of one of the following types:

  • h - move the tape one position to the left. If the tape is already in the leftmost position, do nothing.
  • l - move the tape one position to the right.
  • rx - change the character at the current tape position to x, where x is an arbitrary lower-case English character.

Output Specification

Output the non-blank characters stored on the tape after the instructions are executed. It is guaranteed that at least one character will not be blank.

Sample Input 1

8
rp
l
l
ri
h
h
h
rh

Sample Output 1

hi

Explanation of Sample Input

After the instructions are executed, the tape has ‘h’ stored in the first (leftmost) position and ‘i’ stored in the third position. Removing the blank positions, we are left with the text “hi”.


Comments

There are no comments at the moment.