14624 - Spiderfy Update 1.2.0   

Description

With the success of Spiderfy after only a few weeks, a new major update is planned for the application. Being the lead developer of the application’s launch, you are now tasked with implementing a Play Queue function into the app. This function will allow users to queue up their favorite songs and play them. There are many commands that users want and it is your job to implement it.

Welcome to ‘Spiderfy Streaming Service: Project Q’!

You need to implement a list of songs that repeats itself. At first the list of songs is empty but through certain commands the user can transform the list to their preferences.

Commands:

ADD_SONG N d i

Add a song with the name N and duration d (in seconds) to the list of songs at index i. The list index starts at 0. There is a chance that users may input a value i that exceeds the length of the list, in this case just add the song to the end of the list. We can guarantee that every song has a distinct name and there will be no duplicates.


DELETE_SONG N

Delete a song with the name N. Locate a song based on their name and remove them from the list. If the song does not exist in the list, print out: “Song not found”.

SKIP S

Move number of songs from the front of the list to the back of the list.

REVERSE

Reverse the position of all the songs.

PLAY t

Play the list of songs for t seconds. After t seconds has passed, print out the current playing song. Remember that the list of songs loops to itself. Print it as: “Currently playing: [song name]”. 

DISPLAY

Print out “Playlist Contents:” followed by the list of songs and their duration in the playlist preceded by a “>”. If the playlist is empty follow up with “-- empty --”. After printing the list of songs, regardless if the playlist is empty, print out "Playlist Duration: [total playlist duration] seconds”. (total playlist duration is set to 0 if the list of songs is empty).

Example of empty list:

Playlist Contents:
-- empty --
Playlist Duration: 0 seconds

Notes: Play and Display will always start from index 0

Testcase Difficulty:

Testcase 1: Adding and Removing Songs

Testcase 2: Skip Function

Testcase 3: Skip Function + Reverse Function

Testcase 4: Play Function

Testcase 5: Play Function

(Note that all testcases already account for edge cases

Input

The input consists of the aforementioned list of commands:

  • ADD_SONG N d i

  • DELETE_SONG N

  • SKIP S

  • REVERSE

  • PLAY t

  • DISPLAY

You must do these commands until EOF.

Parameter Constraints:

Parameter Type Size
N string 1 <= len(N) <= 1000
d int 1 <= d <= 300
i int 0 <= i <=10,000
S int 0 <= S <= 10^9
t int 0 <= t <= 10^9
\

Output

Print the outputs required according to each command. Enter a newline after every output unless specified otherwise.

Sample Input  Download

Sample Output  Download




Discuss