#C12225. Filter Students by Grade
Filter Students by Grade
Filter Students by Grade
Given a list of student records where each record consists of a student's name, grade, and average score, your task is to filter the records that match a specified grade. After filtering, sort the records in descending order by average score; if two students have the same average score, sort them in ascending lexicographical order by name. If no student records match the given grade, output the error message:
Formally, if the filtered list is denoted as (S), then (S) should be sorted such that:
$$S[i] > S[j]\ \text{ if }\ averageScore(S[i]) > averageScore(S[j]) \quad \text{or} \quad (averageScore(S[i]) = averageScore(S[j])\ \text{ and }\ name(S[i]) < name(S[j])). $$inputFormat
The input is read from standard input (stdin) and consists of multiple lines:
- The first line contains a string, which is the grade to filter (e.g., "A", "B", etc.).
- The second line contains an integer N, the number of student records.
- Each of the following N lines contains a student record with three values separated by spaces: the student's name (a string without spaces), the student's grade (a string), and the student's average score (an integer).
outputFormat
The output is written to standard output (stdout). If there are matching student records, print each student's record on a separate line in the format: "name grade averageScore" following the sorted order. If no matching record is found, print "No students found with the specified grade." exactly.## sample
A
5
Alice A 92
Bob B 85
Charlie A 88
David B 91
Eve A 92
Alice A 92
Eve A 92
Charlie A 88
</p>