#K36082. Library Book Management

    ID: 25675 Type: Default 1000ms 256MiB

Library Book Management

Library Book Management

You are given a series of commands to manage a library of books. The commands are provided via stdin and the expected results must be printed to stdout. The library stores books as a mapping from a book's title to its author. You need to implement the following operations:

  • ADD title author: Add a new book with the given title and author to the library. If the book already exists, update the author.
  • REMOVE title: Remove the book with the given title from the library.
  • FIND title: Print the author of the book with the given title. If the book is not found, print "Book not found".
  • LIST author: Print all book titles (joined by commas) authored by the given author. If no books by that author exist, print "No books found by this author".

The input starts with an integer n which indicates the number of commands that follow. Then, n lines follow with one command per line. Your program should process the commands in order and output the result for each FIND and LIST command.

Note: If there are multiple book titles for a given author, output them in the order they were added (and not removed) joined by commas.

For example, given the following commands:

ADD HarryPotter J.K.Rowling
ADD TheHobbit J.R.R.Tolkien
ADD HarryPotter J.K.Rowling
REMOVE TheHobbit
FIND HarryPotter
FIND TheHobbit
LIST J.K.Rowling
LIST J.R.R.Tolkien
ADD TheLordOfTheRings J.R.R.Tolkien
LIST J.R.R.Tolkien
REMOVE HarryPotter
LIST J.K.Rowling

The output should be:

J.K.Rowling
Book not found
HarryPotter
No books found by this author
TheLordOfTheRings
No books found by this author

The internal logic of your solution may use a data structure (such as a dictionary or hash map) to keep track of the books.

Additionally, if any mathematical expressions are needed, they should be written in LaTeX format (for example, \(a+b\)).

inputFormat

The first line contains an integer n which is the number of commands. The next n lines each contain one of the following commands:

  • ADD title author
  • REMOVE title
  • FIND title
  • LIST author

Each command and its parameters are separated by whitespace.

outputFormat

For each FIND and LIST command, print the corresponding result on a new line. The results must appear in the order they are processed.

## sample
12
ADD HarryPotter J.K.Rowling
ADD TheHobbit J.R.R.Tolkien
ADD HarryPotter J.K.Rowling
REMOVE TheHobbit
FIND HarryPotter
FIND TheHobbit
LIST J.K.Rowling
LIST J.R.R.Tolkien
ADD TheLordOfTheRings J.R.R.Tolkien
LIST J.R.R.Tolkien
REMOVE HarryPotter
LIST J.K.Rowling
J.K.Rowling

Book not found HarryPotter No books found by this author TheLordOfTheRings No books found by this author

</p>