Means by Group
Vantage Retail is running an experiment in which every checkout is shown one variant of the payment page, and the log records which variant the shopper saw alongside the basket total they ended up paying. Checkouts are written down as they happen, so a variant's lines are scattered all through the file rather than sitting together. The experiment readout wants one line per variant with that variant's average basket.
Task: Print each variant's mean basket value.
Input
The first line holds one integer n, how many checkout lines follow. Each of the next n lines holds a variant name and a basket total, separated by a single space. A variant name is one word with no spaces and is matched exactly, so A and a would be two different variants. A variant may appear any number of times, and its lines are not next to each other.
Output
One line per distinct variant, in alphabetical order by variant name. Each line holds the variant name, one space, then that variant's mean basket with exactly two digits after the decimal point.
Example:
Input:
5
A 10
B 20
A 20
B 40
A 30
Output:
A 20.00
B 30.00
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in