#K66552. Organize Stamp Collection
Organize Stamp Collection
Organize Stamp Collection
Given a series of test cases, each consisting of a collection of stamps represented by their country codes and rarity levels, your task is to compute two things for each test case:
- The number of distinct countries in the collection.
- The average rarity level for the stamps of each country. The average should be computed as \(\frac{\text{sum of rarity levels}}{\text{number of stamps}}\) and displayed with two decimal places.
The country codes must be output in alphabetical order.
Example:
Input: 1 4 USA 50 IND 70 USA 20 IND 30</p>Output: 2 IND 50.00 USA 35.00
inputFormat
The input is read from stdin and has the following format:
- The first line contains an integer T, the number of test cases.
- For each test case, the first line contains an integer N representing the number of stamps.
- This is followed by N lines, each containing a string for the country code and an integer for the rarity level (separated by a space).
outputFormat
For each test case, output the result to stdout in the following format:
- The first line should contain the number of distinct countries.
- This is followed by one line per country, which contains the country code and its average rarity level formatted to exactly two decimal places, separated by a space. The countries must be listed in alphabetical order.
1
4
USA 50
IND 70
USA 20
IND 30
2
IND 50.00
USA 35.00
</p>