Do the Shuffle
InterviewTime limit1sMemory limit128 MB
Simulate a fixed 5-song playlist through button presses that rotate left, rotate right, or swap the first two songs, then print the final order.
- Level
Easy2 of 10
- Topics
- Simulation, Implementation, Array
- Solved
- No attempts yet
Problem
Those tiny music machines that play digital music are really small computers that store and play music files. A new portable music player called the C3MP is in development and will hit stores soon. In this problem you have to simulate a C3MP.
The C3MP holds 5 songs in memory, whose titles are always “A”, “B”, “C”, “D” and “E”. It also keeps a playlist, which is an ordering of all the songs. The player has 4 buttons that rearrange the playlist and play the songs.
Initially the playlist is A, B, C, D, E. The 4 buttons do the following:
- Button 1: move the first song of the playlist to the end. For example, A, B, C, D, E becomes B, C, D, E, A.
- Button 2: move the last song of the playlist to the start. For example, A, B, C, D, E becomes E, A, B, C, D.
- Button 3: swap the first two songs of the playlist. For example, A, B, C, D, E becomes B, A, C, D, E.
- Button 4: stop rearranging and output the playlist.
Input
The input is a sequence of button presses. Each press is given as two positive integers and : is the button number () and is the number of times to press button (). The two integers of a press may be separated by spaces or newlines.
The input always ends with the press , . When you read it, print the current playlist and stop. Button 4 is pressed exactly once, at the very end.
Output
Print the titles of the songs in the final playlist order, on one line, separated by single spaces.