#K64182. Book Sorting

    ID: 31919 Type: Default 1000ms 256MiB

Book Sorting

Book Sorting

You are given a list of books with their title, author, and publication year. Your task is to sort the books primarily by the publication year in descending order, then by the author's name in alphabetical order, and finally by the title in alphabetical order. The sorted list should then be printed to the standard output.

The input is provided via stdin and the output should be sent to stdout. Each book's details are provided on a single line.

Sorting criteria:

  • Year: In descending order (largest year first).
  • Author: In alphabetical order if the years are the same.
  • Title: In alphabetical order if both year and author are the same.

inputFormat

The input begins with an integer n representing the number of books. Each of the following n lines contains a book's details in the format:

title, author, year

Note: Each field is separated by a comma and a space.

outputFormat

Output the sorted list of books, each on a separate line in the same format as the input:

title, author, year## sample
4
Python Programming, John Doe, 2020
Data Science, Jane Smith, 2019
Machine Learning, John Doe, 2020
Data Analysis, Jane Smith, 2020
Data Analysis, Jane Smith, 2020

Machine Learning, John Doe, 2020 Python Programming, John Doe, 2020 Data Science, Jane Smith, 2019

</p>