#C5581. Song Database Management
Song Database Management
Song Database Management
In this problem, you are asked to build a simple song database management system. The system supports the following operations:
- add: Add a song to the database with a unique song identifier, a title, and a duration (in seconds).
- delete: Remove a song from the database using its song identifier.
- total: Compute and output the total duration of all songs in the database. Mathematically, if there are n songs with durations (d_1, d_2, \ldots, d_n), then the total duration is given by (\sum_{i=1}^{n} d_i).
- longest: Find and output the song with the maximum duration. The output should be in the format:
song_id title duration
. If there is no song in the database, outputNone
.
You will receive a series of commands as input. Process each command and output the result for commands total
and longest
.
Note: All input is given via standard input and all output should be written to standard output.
inputFormat
The input begins with a single integer T specifying the total number of commands. This is followed by T lines, each containing one command. The commands can be of the following forms:
-
add id title duration
(\rightarrow) Add a new song with the given id (an integer), title (a string without spaces), and duration (an integer). -
delete id
(\rightarrow) Delete the song with the given id if it exists. -
total
(\rightarrow) Output the total duration of all songs currently in the database. -
longest
(\rightarrow) Output the song id, title, and duration of the song with the maximum duration. If no songs exist, outputNone
.
outputFormat
For each command of type total
or longest
, output the corresponding result on a new line.
For total
, output a single integer representing the sum of durations of all songs.
For longest
, output three space-separated values: the song id, the song title, and the song duration. If there is no song in the database, output None
.## sample
8
add 1 SongOne 210
add 2 SongTwo 320
add 3 SongThree 300
total
longest
delete 2
total
longest
830
2 SongTwo 320
510
3 SongThree 300
</p>