The corner
grocer is a nice guy. Every evening I shop from him and many times I find
him working late to calculate his sales. More specifically, he analyzes the
sales list for that day and sums up these sales by products, thus obtaining
a document called Sales Status.
In the sales list there is a line for each sale made in the form of:
product_name * quantity
Quantity is always expressed in the measuring unit specific to the product.
The product name is separated by the *
(star) character, preceded and followed by a single space.
E.g.:
Swiss Cheese * 2
Tuborg Beer * 6
Cabbage * 1
Tuborg Beer * 2
Swiss Cheese * 3
In the Sales Status, products have to show up in alphabetical order, one product
per line. The line corresponding to a product contains its name followed by
* and then the total quantity
sold. Character * must be preceded
and followed by a single space.
E.g.: for the previous sales list, Sales Status will look as follows:
Cabbage
* 1
Swiss
Cheese * 5
Tuborg
Beer * 8
Because I'm a nice guy and it's not that difficult to write a program
that would generate Sales Status for him, I would like to do this but...
I never have the time.
Task
Write a program that reads the day's sales list and generates the Sales Status.
Input Data
Input file bacan.in contains on the first line a positive integer n representing the number of sales made that day. After that are n lines, each line describing a single sale, in the form specified in the task description.
Output Data
Output file bacan.out will contain on the first line a positive integer p representing the number of distinct products sold that day. The following p lines describe the products sold, in the form specified in the task description.
Constraints and Mentions
bacan.in | bacan.out |
5 |
3 |
Total available memory: 2 MB, of which 1 MB for the stack.
Time limit: 0.2 seconds/test
prof. Marinel Serban
"Grigore Moisil" Iaşi IT High School
Contact:marinel_serban@yahoo.com