#C9410. Book Order Consolidation
Book Order Consolidation
Book Order Consolidation
You are given several book orders. Each order is provided on a separate line with the format <book_title> <number_of_copies>
. The input is terminated by a line containing a single 0.
Your task is to consolidate the orders by summing up the number of copies for each book title and then output the result sorted in alphabetical order by the book title.
In mathematical terms, if a book T is ordered multiple times with counts c1, c2, ..., ck, then the total number of copies for T is given by $$Total = \sum_{i=1}^{k} c_i.$$
If any order does not conform to the expected format, your program should raise an error.
inputFormat
Input is provided via standard input (stdin). Each line represents an order in the format <book_title> <number_of_copies>
. The input ends with a line containing only a single 0.
outputFormat
For each unique book title, output a line to standard output (stdout) in the format <book_title>: <total_copies>
, where total_copies
is the sum of copies for that title. The output must be sorted alphabetically by book title.## sample
HarryPotter 10
0
HarryPotter: 10
</p>