Media Library (II) X13635


Statement
 

pdf   zip

html

A media library is a program used to organise digital audio on a personal computer. Among many other functions, the user can access the attributes of a song, such as: artist, title, genre and year. You have to make a program supporting queries to the media library.

In particular, once the data available on the library has been read by your program, a genre (e.g., Rock) can be introduced to retrieve all the songs belonging to this genre, listed by artist, year and title order.

Use the following program structure, which can not be changed:

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

struct Track {
  string artist, title, genre;
  int year;
};

....
....

vector<Track> read_tracks(int n) {
  ....
  ....
}

void print_track(const Track &t) {
  cout << t.artist;
  cout << " (" << t.year;
  cout << ") " << t.title << " (" << t.genre << ")" << endl;
}

int main() {
  ....
  ....
}

Exam score: 2.5 Automatic part: 0%

Input

The input consists of a number n ≥ 0 followed by n songs, each of which consists of three strings (artist, title and genre) and an integer (year). This is followed by a sequence of strings (genres).

Output

For each genre in the input, print all the songs of that genre sorted by artist and, within artist, by year, and then by title. Follow the format of the test case.

Public test cases
  • Input

    20
    The_Rolling_Stones Start_Me_Up Rock 1981
    The_Rolling_Stones Miss_You Disco 1978
    The_Rolling_Stones Emotional_Rescue Rock 1980
    The_Rolling_Stones Angie Rock 1973
    The_Rolling_Stones Out_Of_Tears Rock 1994
    The_Rolling_Stones Waiting_On_A_Friend Rock 1981
    The_Rolling_Stones Honky_Tonk_Women Rock  1969
    The_Rolling_Stones Rock_And_A_Hard_Place Rock  1989
    The_Rolling_Stones Undercover_Of_The_Night Rock  1983
    The_Rolling_Stones Satisfaction Rock  1965
    The_Beatles Twist_And_Shout Rock  1964
    The_Beatles Hey_Jude Pop  1968
    The_Beatles Got_To_Get_You_Into_My_Life Rock  1966
    The_Beatles Roll_Over_Beethoven Rock 1964
    The_Beatles She_Loves_You Pop 1963
    The_Beatles I_Want_To_Hold_Your_Hand Pop 1963
    The_Beatles Let_It_Be Pop 1970
    The_Beatles Love_Me_Do Pop 1962
    The_Beatles Help Pop 1965
    The_Beatles A_Hard_Day's_Night Pop 1964
    Swing
    Pop
    Rock
    

    Output

    The_Beatles (1962) Love_Me_Do (Pop)
    The_Beatles (1963) I_Want_To_Hold_Your_Hand (Pop)
    The_Beatles (1963) She_Loves_You (Pop)
    The_Beatles (1964) A_Hard_Day's_Night (Pop)
    The_Beatles (1965) Help (Pop)
    The_Beatles (1968) Hey_Jude (Pop)
    The_Beatles (1970) Let_It_Be (Pop)
    The_Beatles (1964) Roll_Over_Beethoven (Rock)
    The_Beatles (1964) Twist_And_Shout (Rock)
    The_Beatles (1966) Got_To_Get_You_Into_My_Life (Rock)
    The_Rolling_Stones (1965) Satisfaction (Rock)
    The_Rolling_Stones (1969) Honky_Tonk_Women (Rock)
    The_Rolling_Stones (1973) Angie (Rock)
    The_Rolling_Stones (1980) Emotional_Rescue (Rock)
    The_Rolling_Stones (1981) Start_Me_Up (Rock)
    The_Rolling_Stones (1981) Waiting_On_A_Friend (Rock)
    The_Rolling_Stones (1983) Undercover_Of_The_Night (Rock)
    The_Rolling_Stones (1989) Rock_And_A_Hard_Place (Rock)
    The_Rolling_Stones (1994) Out_Of_Tears (Rock)
    
  • Information
    Author
    Language
    English
    Translator
    Original language
    Catalan
    Other languages
    Catalan Spanish
    Official solutions
    C++
    User solutions
    C++