#K426. Library Management System

    ID: 27123 Type: Default 1000ms 256MiB

Library Management System

Library Management System

You are given a command based library management system. The system maintains a collection of books. Each book has a unique id, a title, an author, a publication year, and one or more genres.

The system supports the following commands:

  • ADD: Add a new book (command format: ADD id title author year genres, where genres are comma-separated).
  • REMOVE: Remove an existing book by id (command format: REMOVE id).
  • SEARCH TITLE: Search books by a substring in the title (command format: SEARCH TITLE substring). The search is case-insensitive and the result should be sorted by title in lexicographical order.
  • SEARCH GENRE: Search books by a specified genre (command format: SEARCH GENRE genre). The result should be sorted by title in lexicographical order.
  • LIST AUTHOR: List all books by a specific author (command format: LIST AUTHOR author). The result should be sorted in increasing order by publication year.

The first line of input contains an integer m which indicates the number of commands. Each of the following m lines contains one command. Process the commands in order and print the output blocks (if any) for each command that produces output. For commands that produce output, separate each block with two newline characters. If a search or list operation returns no books, output "NO MATCHES".

Note: If a book id already exists, subsequent ADD commands for the same id are ignored, and REMOVE commands for a non-existent id do nothing.

All formulas in this description, if any, use the LaTeX format. For instance, if you wish to denote the number of commands, use \( m \).

inputFormat

The input is provided via standard input (stdin). The first line contains an integer ( m ), the number of commands. The following ( m ) lines each contain a command in one of the following formats:

  1. ADD id title author year genres (Example: ADD 1 The_Great_Gatsby F._Scott_Fitzgerald 1925 Fiction,Classic)

  2. REMOVE id (Example: REMOVE 1)

  3. SEARCH TITLE substring (Example: SEARCH TITLE Gatsby)

  4. SEARCH GENRE genre (Example: SEARCH GENRE Fiction)

  5. LIST AUTHOR author (Example: LIST AUTHOR F._Scott_Fitzgerald)

outputFormat

Output the results of processing commands to standard output (stdout). For each command that produces output (SEARCH and LIST), print the result as follows:

  • If there are matching books, each matching book is printed on a separate line in the format: title, author, year (id) For SEARCH commands, the block of matching books should be printed and blocks for separate commands should be separated by an empty line (i.e., two newline characters).

  • If no books match the criteria, print "NO MATCHES" (without quotes).

Ensure that the output exactly matches the expected format.## sample

5
ADD 1 The_Great_Gatsby F._Scott_Fitzgerald 1925 Fiction,Classic
ADD 2 To_Kill_a_Mockingbird Harper_Lee 1960 Fiction,Classic
SEARCH TITLE Gatsby
REMOVE 1
SEARCH TITLE Gatsby
The_Great_Gatsby, F._Scott_Fitzgerald, 1925 (1)

NO MATCHES

</p>