CCC '24 S1 - Hat Circle


Submit solution

Points: 1
Time limit: 3.0s
Memory limit: 1G

Problem types
Allowed languages
C++, Python
Canadian Computing Competition: 2008 Stage 1, Junior #2

Those tiny music machines that play your digital music are really computers that keep track of and play music files. The CCC music player (C 3 MP) is currently in development and will be hitting the stores soon! In this problem, you have to simulate a C 3 MP.

The C 3 MP music player will hold 5 songs in memory, whose titles will always be "A", "B", "C", "D" and "E". The C 3 MP also keeps track of a playlist , which is an ordering of all the songs. The C 3 MP has 4 buttons that the user will press to rearrange the playlist and play the songs.

Initially, the C 3 MP playlist is "A, B, C, D, E". The 4 control buttons do the following:

  • Button 1: move the first song of the playlist to the end of the playlist. For example: "A, B, C, D, E" will change to "B, C, D, E, A".
  • Button 2: move the last song of the playlist to the start of the playlist. For example, "A, B, C, D, E" will change to "E, A, B, C, D".
  • Button 3: swap the first two songs of the playlist. For example, "A, B, C, D, E" will change to "B, A, C, D, E".
  • Button 4: stop rearranging songs and output the playlist.

You need to write a program to simulate a CCC music player. Your program should repeatedly ask for two positive integers \(b\) and \(n\) . Here \(b\) represents the button number that the user wants to press, \(1 \le b \le 4\) , and \(n\) represents the number of times that the user wants to press button \(b\) . You can assume that \(n\) always satisfies \(1 \le n \le 10\) .

The input will always finish with the pair of inputs ( \(b = 4\) , \(n = 1\) ) when this happens, you should print the order of songs in the current playlist and your program should end. You can assume that the user will only ever press button 4 once.

Sample Input

2
1
3
1
2
3
4
1

Output for Sample Input

B C D A E

Explanation

  • (initial playlist is "A, B, C, D, E")
  • ( \(b = 2\) , \(n = 1\) so "A, B, C, D, E" changed to "E, A, B, C, D")
  • ( \(b = 3\) , \(n = 1\) , so "E, A, B, C, D" changed to "A, E, B, C, D")
  • ( \(b = 2\) , \(n = 3\) , so "A, E, B, C, D" changed to "B, C, D, A, E")
  • Output a single integer representing the number of people who see their hat number on the person directly across from them.

    Sample Input 1

4
0
1
0
1

Output for Sample Input 1

4

Explanation for Output for Sample Input 1

The four seats around the table are shown below. Hat numbers are shown inside each seat and seat numbers are shown beside each seat. Notice that every person sees their hat number. The people in seats \(1\) and \(3\) both see hat number \(0\) , and the people in seats \(2\) and \(4\) both see hat number \(1\) .

Sample Input 2

4
1
0
0
1

Output for Sample Input 2

0

Explanation for Output for Sample Input 2

The four seats around the table are shown below. Hat numbers are shown inside each seat and seat numbers are shown beside each seat. Notice that no person sees their hat number. The people in seats \(1\) and \(4\) both see hat number \(0\) , and the people in seats \(2\) and \(3\) both see hat number \(1\) .


Comments

There are no comments at the moment.