Topic description
A primary school has recently received a sponsorship, and plans to take part in scholarships for the top 5 students with outstanding academic performance. At the end of the semester, each student has 3 subjects: Chinese, maths and English. First, according to the total score from high to low order, if two students score the same, and then according to Chinese grades from high to low ranking, if two students total score and language results are the same, then the rules of the small students ranked in the front, so that the ranking of each student is the only determined.
Task: First, according to the input of the 3 courses to calculate the total score, and then sorted by the above rules, and finally ranked in order to output the first five students of the number and total score. Note that among the top 5 students, each scholarship is not the same, so you have to sort it strictly according to the rules. For example, in a correct answer, if the first two lines of output data (two per line output: School number, total score) is:
7 279
5 279
The meaning of these two lines of data is: the number of the two students with the highest score is 7th, 5th. The total score of these two students is 279 (total score equals the sum of the three subjects of Chinese, maths and English), but the students with a number of 7 are higher in Chinese. If your first two output data is:
5 279
7 279
The output error is handled and the score cannot be scored.
Input
Contains n+1 lines: The 1th act a positive integer n, indicating the number of students enrolled in the school.
The 2nd to N+1 line, each line has 3 numbers separated by spaces, each number is between 0 and 100. The 3 digits in line J indicate the Chinese, maths, and English grades of the students who j-1 the school number. Each student's school number is numbered 1~n (just the line number minus 1 of the input data) according to the input order. The data given are correct and do not need to be tested.
Output
There are 5 rows, each of which is two positive integers separated by spaces, which in turn represent the number and total score of the first 5 students.
Sample input
6
90 67 80
87 66 91
78 89 91
88 99 77
67 89 64
78 89 98
Sample output
6 265
4 264
3 258
2 244
1 237
Train of thought: we use the sort function to order the structure, first write a CMP comparison function, if the score is different, then in descending order, if the score is the same, ① language results, in descending order of language results,
② If the language results are the same, then according to the school number in ascending order.
Code:
Include include
using namespace Std;
struct scholarship{
int num,chinese,math,english,total;
};
BOOL CMP (Scholarship a,scholarship B)
{
if (a.total!=b.total)
Return a.total>b.total;
else if (A.chinese!=b.chinese)
Return a.chinese>b.chinese;
Return A.num