| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 10895 | Grade report(different order) |
|
Description
Given a grade report for all students in a class, which includes student ID, Chinese grade, English grade, math grade, and science grade for each student. Please list the report sorted in two different way.
If the order is descending, sort the grade by the total grade from high to low. If the total grade is the same between two students, then sort by order of Chinese grade, English grade, math grade, science grade, and student ID, which is from high to low for all grades and from low to high for student ID.
If the order is ascending, sort the grade by the total grade from low to high. If the total grade is the same between two students, then sort by order of Chinese grade, English grade, math grade, science grade, and student ID, which is from low to high for all grades and from low to high for student ID.
Note that in both two way, the student ID is sorted from low to high.
You need to store these information in structures:
typedef struct
{
int ID;
int Chinese, English, math, science;
int total;
} Grade;
HINT
Hint: While sorting, you can use qsort in <stdlib.h> or write other sorting algorithms by your self.
function.h
main.c
Input
The first line contains an integer N and a string, which means the number of students in the class and the order which grade are sorting in respectively.
In the following N lines, there are 5 integers: student ID, Chinese grade, English grade, math grade, and science grade in each line in order, which are separate by spaces.
Output
List the sorted report, while each line contains student ID, total grade, Chinese grade, English grade, math grade, and science grade in order, where there is a '\t' between each number. Note that there is a '\n' at the end of each line.