CCC '08 J2 - Do the Shuffle

View as PDF

Submit solution

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

Problem type
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 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

  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.

Comments


  • 1
    Misaka  commented on Oct. 6, 2022, 10:57 p.m. edit 5

    Hi, can anyone help me? I got the same output as the sample but the judging system gave IR to all my responses.

    Sorry!! I saw the RAM is out of the limit!! Sorry for the interruption!


  • 1
    QooModa  commented on Feb. 22, 2022, 9:59 a.m.

    Hi everyone!

    Would like some tips on how to make my code more elegant.

    For the output, used I printed a string created manually "iterating" each of the elements of the list I used to manipulate the list. But it looks very ugly.

    Any other tips?

    Thanks


    • 2
      Spitfire720  commented on Feb. 22, 2022, 10:04 a.m.

      Your line to print the playlist can actually be shortened down thanks to a function in Python.

      Instead of adding all the songs together, you can do this:

      print(" ".join(playlist))
      

      This will concatenate the strings with a space in between each string.

      You can also check if the input is 4 instead of using a boolean.


  • 2
    iWolf22  commented on Dec. 12, 2020, 1:33 p.m.

    My code seems to work in Visual Studios, but I get WA? Any help would be greatly appreciated! (python)


    • 3
      Badmode  commented on Dec. 12, 2020, 7:47 p.m.

      Read this in the input specification:

      "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 ≤ b ≤ 4, and n represents the number of times that the user wants to press button b. You can assume that n always satisfies 1 ≤ n ≤ 10."

      Your code seems to only accept the integer "b" and not the integer "n."

      So if the user inputs:

      1
      1
      4
      1

      Your program will swap A and B two times then output the result.

      A B C D E

      Your program should swap A and B one time and output the result.

      B A C D E

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

    I think I will use an array


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

      This comment is hidden due to too much negative feedback. Show it anyway.


      • 1
        QiQi  commented on Nov. 20, 2021, 9:52 p.m.

        I think everyone used a array (arraylist included )or a list (depends on the language(s) you use).


        • 2
          dizmac  commented on Nov. 21, 2021, 2:22 p.m. edited

          No, you can use an ArrayDeque as well.