Title Description
A primary school recently received a sum of sponsorship, which intends to come up with as part of the academic excellence of the top five student scholarship. Period, each student has a 3 course achievements: language, mathematics, English. Press out the sort from high to low, if two students the same score, then language scores in descending order, if two students scores and language scores are the same, then the provisions of a small number of students standing in the front of school so, ordering each student is uniquely determined.
Task: first calculate the total score based on input 3 course results, and then sort by the above rules, the final output order of rank the top five students in school number and total score. Note that in the previous five students, scholarships are not the same for everyone, so you must be sorted in strict accordance with the above rules. For example, in one correct answer, if the output data of the first two lines (two per output line: school, total score) are:
77 279279
55 279279
The data is the meaning of these two lines: two students score the highest number of school followed by 7 7, 5 No. 5. The two students out of all 279 2 7 9 (score equals the input language, mathematics, English and the three subjects), but school No. 7 higher student achievement 7 languages. If your top two output data is:
55 279279
77 279279
Press output error handling, can not score.
Input and output formats
Input formats:
Total row n + 1.
The first 1 1 conduct a positive integer the n-(\ Le 300) the n- ( ≤ 3 0 0 ), represents the number of students participate in the selection of the school.
Of 2 2 through n-+. 1 n- + . 1 line per line . 3 three numbers separated by spaces, each digit in 0 0 to 100 . 1 0 0. The first J J line 3 3 digit student number in turn expressed as J-1 J - students of grades 1 language, mathematics, English. Each student in school number input order numbered . 1 ~ n- . 1 n-(exactly minus the line number of the input data . 1 1).
The given data are correct, do not test.
// thank Huang U drinks corrects the input format
Output formats:
A total of five lines, each line are two positive integers separated by a space, followed by a front 5 5 student's student number and total score.
Sample input and output
6 90 67 80 87 66 91 78 89 91 88 99 77 67 89 64 78 89 98
6 265 4 264 3 258 2 244 1 237
8 80 89 89 88 98 78 90 67 80 87 66 91 78 89 91 88 99 77 67 89 64 78 89 98
8 265 2 264 6 264 1 258 5 258
#include<bits/stdc++.h> using namespace std; struct node{ int sum,chinese,math,english,num; }a[305]; bool cmpp(node x,node y){ if(x.sum!=y.sum){ return x.sum>y.sum; } if(x.chinese!=y.chinese){ return x.chinese>y.chinese; } return x.num<y.num; } int main(){ int n; cin>>n; for(int i=1;i<=n;++i){ scanf("%d%d%d",&a[i].chinese,&a[i].math,&a[i].english); a[i].num=i; a[i].sum=a[i].chinese+a[i].math+a[i].english; } sort(a+1,a+1+n,cmpp); for(int i=1;i<=5;++i){ printf("%d %d\n",a[i].num,a[i].sum); } }