#C6864. Book Collection Manager
Book Collection Manager
Book Collection Manager
You are given the task of implementing a BookCollection data structure that maintains a collection of books. Each book has a unique identifier, a title, and an author.
The data structure must support the following two operations:
- ADD: Add a book to the collection. The input for this command will be a book ID (an integer), a title (a string), and an author (a string). Upon adding a book, you should update the count of books for that author.
- QUERY: Output the author with the highest number of books in the collection. In mathematical terms, if we denote the count of books for author a as \(c(a)\), you must output an author \(a^*\) such that \(c(a^*) = \max_{a} c(a)\). If the collection is empty, output
None
.
If there is a tie (i.e. two or more authors have the same maximum count), you may output any one of them.
Note: The input will be processed from standard input (stdin) and the output should be printed to standard output (stdout).
inputFormat
The first line contains an integer \(n\) representing the number of operations.
Each of the following operations is provided in sequence. There are two types of operations:
- If the operation is ADD, the next three lines contain:
- An integer
book_id
- A string
title
(can contain spaces) - A string
author
(can contain spaces) - If the operation is QUERY, no additional lines follow and you must output the most common author at that point.
It is guaranteed that all operations are valid.
outputFormat
For each QUERY operation, print a single line containing the author with the most books in the collection. If no books have been added at the time of a query, print None
.
6
QUERY
ADD
1
The Fellowship of the Ring
J.R.R. Tolkien
QUERY
ADD
2
The Two Towers
J.R.R. Tolkien
QUERY
None
J.R.R. Tolkien
J.R.R. Tolkien
</p>