CCC '08 J2 - Do the Shuffle

View as PDF

Submit solution

Points: 3
Time limit: 2.0s
Memory limit: 64M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig
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 (C3MP) is currently in development and will be hitting the stores soon! In this problem, you have to simulate a C3MP.

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

Initially, the C3MP playist 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


Output for Sample Input



  1. (initial playlist is "A, B, C, D, E")
  2. (b = 2, n = 1 so "A, B, C, D, E" changed to "E, A, B, C, D")
  3. (b = 3, n = 1, so "E, A, B, C, D" changed to "A, E, B, C, D")
  4. (b = 2, n = 3, so "A, E, B, C, D" changed to "B, C, D, A, E")
  5. (b = 4, n = 1) When this happens, you should output the playlist.


  • 0
    tl0x  commented on Sept. 2, 2020, 3:37 p.m.

    What's wrong with my code?

  • -2
    WEAVER  commented on April 29, 2019, 5:44 p.m.

    Way too normal dificulty

  • -2
    keewanyayi288517  commented on Oct. 13, 2018, 9:19 p.m.

    I think I will use an array

    • -4
      andisong  commented on Feb. 10, 2019, 8:34 a.m.

      I tinky tink i vill uze a array too

  • -10
    Kirito  commented on June 27, 2016, 11:28 p.m.

    This comment is hidden due to too much negative feedback. Click here to view it.

    • 3
      quantum  commented on June 29, 2016, 1:43 a.m.

      Waterloo PDFs likes to use the ligature LATIN SMALL LIGATURE FI (U+FB01), which is fi instead of the actual string fi.