#C13743. Student Grade Categorization

    ID: 43315 Type: Default 1000ms 256MiB

Student Grade Categorization

Student Grade Categorization

You are given a list of students along with their numerical grades. Your task is to categorize each student into one of the following performance groups:

  • Excellent: grades strictly greater than \(90\).
  • Good: grades between \(75\) and \(90\) (inclusive).
  • Average: grades between \(50\) and \(74\) (inclusive).
  • Poor: grades below \(50\).

The program must also offer an option to sort the student names within each category either in ascending or descending order of their grades. In case of invalid input (such as an empty student name or a grade outside the range \([0, 100]\)), the program should report an error by raising an exception. For this contest problem however, you only need to handle valid inputs.

inputFormat

The input is given via standard input (stdin) in the following format:

  1. The first line contains a string indicating the sort order. It will be either ascending or descending.
  2. The second line contains a single integer \(n\), the number of students.
  3. The next \(n\) lines each contain a student's name and grade separated by a space. The grade is a number between 0 and 100.

outputFormat

The output should be printed to standard output (stdout) as a single line string representing a Python-style dictionary. The keys in the dictionary are Excellent, Good, Average, and Poor, each mapping to a list of student names belonging to that category. The names in each list must be sorted according to the specified sort order (by their grades).

For example:

{"Excellent": ["Alice"], "Good": ["Bob"], "Average": ["Charlie"], "Poor": ["Daisy"]}
## sample
ascending
4
Alice 95
Bob 80
Charlie 66
Daisy 45
{"Excellent": ["Alice"], "Good": ["Bob"], "Average": ["Charlie"], "Poor": ["Daisy"]}