#K37967. Group Students by Grades

    ID: 26094 Type: Default 1000ms 256MiB

Group Students by Grades

Group Students by Grades

You are given a list of students each with a name and a grade. Your task is to group the students by their grade and output each grade along with the list of student names sorted in ascending alphabetical order.

The input is read from standard input and the output is written to standard output. For each grade group, output the grade followed by a colon and a space separated list of corresponding student names. The grade groups must be listed in ascending order.

Note: If there are any formulas in the problem statement, they should be formatted using LaTeX. In this case, although no formulas are given, if needed you may use the syntax \( ... \) or \[ ... \] for inline or display formulas respectively.

inputFormat

The input is given from standard input in the following format:

  • The first line contains an integer \( n \) denoting the number of students.
  • Each of the next \( n \) lines contains a student name (a string without spaces) and an integer grade, separated by a space.

For example:

5
John 88
Emma 90
Sophia 88
Mike 75
Alice 90

outputFormat

For each unique grade, output a line in the following format:

grade: name1 name2 ... namek

Here, the student names are sorted in ascending alphabetical order and the grades are printed in ascending order. For the example above, the output should be:

75: Mike
88: John Sophia
90: Alice Emma
## sample
5
John 88
Emma 90
Sophia 88
Mike 75
Alice 90
75: Mike

88: John Sophia 90: Alice Emma

</p>