#C13762. Filter Books by Genre and Year

    ID: 43336 Type: Default 1000ms 256MiB

Filter Books by Genre and Year

Filter Books by Genre and Year

You are given a list of books, where each book is defined by its title, author, year of publication, and genre. Your task is to filter these books based on a specified genre and a year threshold. Specifically, you must output the list of book titles that belong to the provided genre and have a publication year strictly greater than the given threshold. The resulting titles should be sorted in lexicographical (alphabetical) order.

Mathematically, if a book is represented as a tuple \((title, author, year, genre)\), you must output all titles for which: \(\text{genre} = G\) and \(\text{year} > Y\).

inputFormat

The input is read from standard input (stdin) and is formatted as follows:

  1. An integer \(n\) representing the number of books.
  2. The next \(n\) lines each contain a book description in the format: title,author,year,genre. The fields are separated by commas.
  3. A line containing a string \(G\), representing the genre to filter by.
  4. A line containing an integer \(Y\), the year threshold; only books with a publication year strictly greater than \(Y\) will be included.

outputFormat

Output to standard output (stdout) a single line containing the sorted list of book titles that match the criteria, separated by a single space. If no books match the criteria, output an empty line.

## sample
6
Book1,Author1,1987,Fiction
Book2,Author2,1995,Science
Book3,Author3,2000,Fiction
Book4,Author4,2010,History
Book5,Author5,2015,Fiction
Book6,Author6,2020,Science
Fiction
1990
Book3 Book5

</p>