#C145. Classroom Management System

    ID: 44155 Type: Default 1000ms 256MiB

Classroom Management System

Classroom Management System

You are given a series of commands to manage a classroom. The classroom initially is empty. The following operations are supported:

  • add name grade: Add a student with the given name (a string without spaces) and grade (an integer).
  • remove name: Remove all students with the given name from the class.
  • average: Calculate and output the average grade of the current students. If there are no students, output 0.0. The average must be printed as a floating-point number with exactly one decimal place.
  • sort: Sort the students by their grade in ascending order and output each student on a new line in the format name grade. If there are no students, output a single line containing "Empty".

Implement the Classroom Management System so that it processes commands from standard input and outputs the result of the average and sort commands to standard output.

Formally, if we denote by \( S \) the set of students with grades, then the average grade is given by \( \text{avg} = \frac{1}{|S|} \sum_{s \in S} \text{grade}(s) \) (with the convention that if \( |S| = 0 \), then \( \text{avg} = 0.0 \)).

inputFormat

The first line of input contains an integer T denoting the number of commands. Each of the following T lines contains a command in one of the following forms:

  • add name grade
  • remove name
  • average
  • sort

Commands are processed sequentially.

outputFormat

Every time an average command is encountered, output a single line with the average grade (printed as a floating-point number with one decimal place). For every sort command, output the sorted list of students (each on a new line in the format name grade). If there are no students at the point when a sort command is given, output a single line containing "Empty".

## sample
4
add Alice 85
average
add Bob 90
average
85.0

87.5

</p>