#C7437. Too Many Books
Too Many Books
Too Many Books
Problem Description:
You are required to implement a program to manage a digital book collection. The collection supports the following commands:
- (\texttt{ADD\ x\ g}): Adds a new book with unique ID (x) to genre (g). If the book already exists, ignore the command.
- (\texttt{MOVE\ x\ g}): Moves an existing book with ID (x) to genre (g). If the book does not exist or the new genre is the same as its current genre, ignore the command.
- (\texttt{COUNT\ g}): Outputs the number of books in genre (g).
Initially, the collection is empty. You are given (Q) commands from standard input. Process each command and, for every (\texttt{COUNT}) command, print the corresponding result on a separate line.
inputFormat
Input Format:
The first line contains an integer (Q) ((1 \le Q \le 10^5)) representing the number of commands. Each of the following (Q) lines contains one command in one of the following formats:
- (\texttt{ADD\ x\ g})
- (\texttt{MOVE\ x\ g})
- (\texttt{COUNT\ g})
Here, (x) and (g) are integers representing the book ID and genre respectively.
outputFormat
Output Format:
For each (\texttt{COUNT}) command, output the number of books in the requested genre on a separate line.## sample
6
ADD 1 10
ADD 2 10
ADD 3 20
COUNT 10
COUNT 20
COUNT 30
2
1
0
</p>