#C7598. Sports Report Generator
Sports Report Generator
Sports Report Generator
You are given a list of sports and a list of entries where each entry contains a sport name, a student's name, and their skill level. Your task is to generate a report. The report should list each sport in lexicographical order. Under each sport, list the participants sorted primarily by their skill levels in descending order and, in case of ties, by their names in ascending lexicographical order.
In mathematical notation, if a participant is represented by a tuple \((name, s)\) where \(s\) is the skill level, then for two participants \((name_1, s_1)\) and \((name_2, s_2)\) in the same sport, \((name_1, s_1)\) should appear before \((name_2, s_2)\) if and only if \[ s_1 > s_2 \quad \text{or} \quad (s_1 = s_2 \text{ and } name_1 < name_2). \]
The report is printed to stdout
, with each sport or participant on a new line.
inputFormat
The input is read from stdin and has the following format:
<s> <p> Sport_1 Sport_2 ... (total s lines for sports) Entry_1 Entry_2 ... (total p lines for entries)
Each entry is given as three space-separated values: a sport name, a student's name, and an integer indicating the student's skill level.
outputFormat
Print the report to stdout. For each sport (in lexicographical order):
- Print the sport name on a new line.
- If there are participants for that sport, print each participant on a new line in the format
student_name skill
, sorted by descending skill and then by ascending lexicographical order of the name if skills are equal.
3 5
badminton
football
chess
football john 85
chess alice 90
badminton bob 78
football marina 95
badminton alice 82
badminton
alice 82
bob 78
chess
alice 90
football
marina 95
john 85
</p>