#K6376. Book Sales Report
Book Sales Report
Book Sales Report
In this problem, you are given a series of book inventories and sales transactions for one or more genres. For each genre, you will receive the list of books available and a list of sales transactions. Your task is to generate a sales report for each genre showing only the books that achieved at least one sale. The books in each genre must be sorted in descending order of copies sold. In the case of a tie in copies sold, sort the books in lexicographical order (i.e. alphabetically) by their title.
Formally, let (T) denote the number of test cases. For each test case, you are given an integer (G) representing the number of genres. For each genre:
- The genre name as a string.
- An integer (B) representing the number of books.
- (B) lines each representing a book record in the format:
book_id,title,author,copies_available
. - An integer (S) representing the number of sales transactions.
- (S) lines each representing a sales transaction in the format:
book_id,copies_sold
.
The output for each genre starts with the genre name on a new line. Then, for each book with at least one sale, output one line in the format: title, copies_sold
following the sorted order as described. Use standard input and standard output for reading and writing data.
inputFormat
The input is read from standard input (stdin) with the following structure:
- The first line contains an integer (T), the number of test cases.
For each test case:
- The first line contains an integer (G), the number of genres.
For each genre: - A line containing the genre name. - A line containing an integer (B), the number of books. - (B) lines each containing a book record in the format: book_id,title,author,copies_available - A line containing an integer (S), the number of sales transactions. - (S) lines each containing a transaction in the format: book_id,copies_sold
Note: There is no extra whitespace at the beginning or end of each line.
outputFormat
For each genre in the test case, the first line of the output is the genre name. For each book in that genre that has at least one sale, output a line in the format:
title, copies_sold
Make sure books are sorted by descending copies sold and, in the event of a tie, by lexicographical order of the title. The output is written to standard output (stdout).## sample
2
1
Fantasy
3
1,The Hobbit,J.R.R. Tolkien,100
2,Harry Potter,J.K. Rowling,50
3,The Witcher,Andrzej Sapkowski,20
5
1,10
2,20
3,10
2,3
1,5
1
Science Fiction
3
4,Dune,Frank Herbert,60
5,Neuromancer,William Gibson,40
6,Foundation,Isaac Asimov,30
4
5,15
4,40
6,12
5,10
Fantasy
Harry Potter, 23
The Hobbit, 15
The Witcher, 10
Science Fiction
Dune, 40
Neuromancer, 25
Foundation, 12
</p>