Top k per stage
Make the game log a record, and group, count and sort it with query pipelines (C# LINQ, Java streams) instead of loops.
The first line has the number of entries n and k, and the next n lines have one entry each as "stage player score".
A player may have played the same stage several times.
For each stage, a player's score is the single highest score they got on that stage.
For each stage, order the players by score from high to low, and on equal scores by name in code order (ASCII, uppercase before lowercase).
Print the number of stages on the first line.
Then, for each stage in code order of the stage name, print one line "stage players name:score ...".
players is the number of different players who played that stage, followed by the first k players separated by spaces.
If there are fewer than k players, list them all.
Names are case-sensitive, so Ann and ann are different players.
- Input
- 1 ≤ n ≤ 5000, 1 ≤ k ≤ 10.
Stage names are 1 to 8 lowercase English letters, and there are at most 100 different stages.
Player names are 1 to 8 English letters, upper or lower case.
0 ≤ score ≤ 1,000,000,000 (integer) - Output
- the number of stages, then one line per stage
6 2 cave ann 50 sky Bob 7 cave bob 70 cave ann 90 sky adam 7 cave Ann 70
2 cave 3 ann:90 Ann:70 sky 2 Bob:7 adam:7
5 3 moon zed 4 beach Zed 4 moon Zed 9 moon zed 9 moon eve 1
2 beach 1 Zed:4 moon 3 Zed:9 zed:9 eve:1