#C4833. Bookstore Sales Manager
Bookstore Sales Manager
Bookstore Sales Manager
You are given a series of commands to manage a bookstore's inventory and sales records. There are three types of commands:
ADD <isbn> "<title>"
: Adds a new book with the provided ISBN and title. The initial sales for the book is 0.UPDATE <isbn> <sales>
: Updates the sales record of the book by adding the specified number of sales. In mathematical form, if the previous sales is \(s_{prev}\) then the new sales is \(s = s_{prev} + s_{new}\).QUERY <isbn>
: Outputs the current total sales of the book with the given ISBN. If the book does not exist, it outputs 0.
Your task is to process the commands, maintain the bookstore records, and print the results of the QUERY commands.
inputFormat
The input is given via standard input (stdin). The first line contains an integer (n) representing the number of commands. Each of the next (n) lines contains a command in one of the following formats:
• ADD "" • UPDATE • QUERY
Note: The ISBN is a unique string for each book, and may contain spaces. The sales value is a non-negative integer.
outputFormat
For every QUERY command encountered, output the total number of sales for the specified book on a new line via standard output (stdout). If a book with the given ISBN does not exist, output 0.## sample
6
ADD 9780131103627 "The C Programming Language"
ADD 9780131101630 "The UNIX Programming Environment"
UPDATE 9780131103627 100
UPDATE 9780131101630 50
QUERY 9780131103627
QUERY 9780131101630
100
50
</p>