#K88902. Student Database Operations
Student Database Operations
Student Database Operations
You are given a student database that supports three operations:
- INSERT name grade: Insert a new student record with the given
name
(a string) andgrade
(an integer). If the student already exists, update their grade. - DELETE name: Delete the student record for the specified
name
. If the student does not exist, ignore the command. - TOP n: Query the top
n
students with the highest grades. In case of ties, students are ordered in lexicographical order by their names. If there are no students, output "No students".
The commands are given one per line. Your task is to process all the operations and for each TOP
command, output the corresponding result records.
Note: All formulas (if any) should be represented in LaTeX format. For example, the sorting criteria can be denoted as: \(\text{Sort by } ( -grade, name )\).
inputFormat
The input is provided via stdin and consists of multiple lines. Each line contains a single operation command in one of the following formats:
INSERT name grade
DELETE name
TOP n
The input terminates at the end of file.
outputFormat
For each TOP
command from the input, output the result records on separate lines in the order they are retrieved. Each record should be in the format name grade
. If there are no students in the database when a TOP
command is issued, output exactly No students
.
The output should be written to stdout.
## sampleINSERT Alice 90
INSERT Bob 85
INSERT Charlie 90
TOP 2
Alice 90
Charlie 90
</p>