# | Problem | Pass Rate (passed user / total user) |
---|---|---|
14598 | Spiderfy Streaming Service: Project Playlist |
|
Description
STL related to Data Structures (such as stack
, queue
, deque
, map
, unordered_map
, set
, unordered_set
, priority_queue
, etc.) are not allowed.
All other STL libraries can be used.
After just a full year of its launch, the delivery service app is performing extremely well, thanks to your routing algorithm from Project Dijkstra (refer to question 14311 for backstory). Now that you’re an experienced developer you decided to start a new project on your own that will complement the delivery app, Spiderfy! This new app will let delivery men stream their favorite music while delivering food to their clients. Your task is to develop a program that will allow users to create a library that collects a certain amount of song playlists as specified by the user. The program will also allow the user to “search” for songs letter-by-letter, and when given the specified command, add them to the corresponding playlists created. Handle any other commands accordingly. Welcome to ‘Spiderfy Streaming Service: Project Playlist’!
Commands:
Char
char represents a character immediately followed by a newline, this indicates that the user is “typing” a character to form a song name. Insert the ‘typed’ character after the position of the cursor, and move the cursor to the recently added character.
ADD ls
This command indicates that the user is done “typing” the current song name. All previous characters typed will form the song name and the song will be added to the playlist ls. Once the song has been added to the playlist, clear all the characters typed to form the previous song name.
CURSOR i d
Move the cursor by i positions in the d direction (either Left or Right) from the initial cursor’s position. Where i is an integer and d is a character. The cursor is at the “tail” of the word by default when typing a new song name unless moved.
Ex:
CURSOR 2 L
1->2->3* (* cursor is at 3)
1*->2->3 (* cursor is now at 1)
*Refer to the homework video for detailed visualization.
MOVE ls p i d
Rearrange song, this command will move the song at the p position (counting from the head of the list) in the ls playlist by i positions in the d direction (either Left or Right) from the chosen song’s initial position. Where p and i are integers and d is a character. The first song in the playlist is in position “1”.
MOVE 1 3 2 L
1->2->3->4
3->1->2->4
*Refer to the homework video for detailed visualization.
REVERSE ls k
Group the songs into k songs per group. Then reverse the order of the song within each group. If the group is lesser than k, reverse it anyways. If the playlist is currently empty, please output: “Playlist {ls} is empty”.
SAVE ls
The user is done adding songs to the ls playlist for now, print out the songs in the playlists. First print the playlist title “Playlist {ls}:”.
The next n lines will be as follow, where n is the number of songs in the list: “> {SONG_NAME}”
Each line will be the name of each song starting from the “head” of the playlist followed by a newline character; there's one whitespace between the “>” character and the song name.
However, if there are no songs in the playlist, please ignore the above output requirements and simply print: “Playlist {ls} is empty”.
Guarantees & Notes:
- It is guaranteed that i value in the CURSOR command will not be greater than +1 position away from the head, and will not be greater than the tail.
- CURSOR command will only occur when there is at least one character in the search bar.
- REVERSE is guaranteed to happen when there are at least 2 or more songs in the playlist.
- MOVE will not occur when there’s less than 3 songs in the playlist.
- It is guaranteed that the MOVE distance will not exceed the head and tail of the list.
- It is guaranteed that each song’s name will not exceed 12 characters (≤ 12 characters).
- The value of ls is guaranteed to exist.
- The first playlist is playlist number 1. (Start counting from 1, not 0)
Input
The first input line will contain an integer s which will specify the number of empty playlists the user has in their library.
The following input lines will be one of the following commands:
- Char
- ADD ls
- CURSOR i d
- MOVE ls p i d
- REVERSE ls k
- SAVE ls
And will come in stream until End of File (you can use getline() and while-loop, to achieve this). Each line will correspond to a single “command”.
Param. name | Details | Size |
s | The no. of playlists in a user’s library | 1 ≤ s ≤ 10 |
p | Position of the target song | 1 ≤ p ≤ current no. of songs in playlist |
i | The number of positions away from the selected object’s initial position. | 2 ≤ i ≤ current no. of songs in playlist - p |
d | Direction to traverse the linked list (left or right) | d = “L” or “R” (“L” for left, “R” for right) |
k | The group size for reverse linked list command | 2 ≤ k ≤ 5,000 |
ls | Playlist number to perform action on | 1 ≤ ls ≤ s |
char | A single character | “a-z”, “A-Z”, “0-9” |
Output
Print the outputs required according to each command. Enter a newline after every output unless specified otherwise.