#K48092. Bookstore Inventory and Sales Report

    ID: 28343 Type: Default 1000ms 256MiB

Bookstore Inventory and Sales Report

Bookstore Inventory and Sales Report

An online bookstore needs a simple inventory management system. The system supports three operations:

  • ADD: Add a new book or update an existing book. The command is followed by book_id (integer), title (string), author (string), genre (string), price (float), and stock (integer).
  • SALE: Process a sale for a book identified by book_id. This command is followed by the number of copies to sell. A sale is successful only if the stock is sufficient; otherwise, no sale is processed.
  • REPORT: Generate a sales report. The report prints, for each genre, the total number of copies sold and the total sales amount. Finally, it prints the overall total sales amount for the bookstore.

The sales amount for each sale is calculated as \(price \times copies\), and all amounts should be formatted to two decimal places.

inputFormat

The first line contains an integer \(N\) (the number of commands). Each of the next \(N\) lines contains one command. Each command is in one of the following formats:

  • ADD book_id title author genre price stock
  • SALE book_id copies
  • REPORT (this command will always be the last line)

Note: The strings for title, author, and genre will not contain spaces.

outputFormat

For each genre which appears in the inventory, output a line in the following format:

genre total_copies_sold total_sales_amount

After listing all genres (in the order they are first added), print a final line:

total_sales overall_total_sales_amount

All sales amounts should be displayed with exactly two decimal places.

## sample
3
ADD 1 BookOne AuthorOne Fiction 10.99 50
SALE 1 5
REPORT
Fiction 5 54.95

total_sales 54.95

</p>