Scholarship---Sort

Source: Internet
Author: User

Title Description:

A primary school has recently received a sponsorship, and intends to take part in a scholarship for the top 5 students with outstanding academic performance. At the end of the semester, each student has 3 subjects: Chinese, maths, English. First, according to the total score from high to low, if the two students with the same total score, and then according to the language scores from high to low sort, if the total score of two students and the same language scores, then the number of students in the order of the students ranked in front, so that each student's sort is the only certainty.

Task: First calculate the total score according to the results of the 3 courses entered, then sort according to the above rules, and finally output the first five students ' number and total score in order of rank. Note that in the top 5 students, each person's scholarship is different, so you must strictly according to the above rules and order. For example, in a correct answer, if the output data for the first two rows (two numbers per line: study number, total score) is:

7 279

5 279

The meaning of these two lines of data is: The highest total score of two students of the school number is 7th, 5th number. The total score of the two students is 279 (total is equal to the input of the language, mathematics, English, the sum of the three subjects), but the student number of 7 of the students have a higher Chinese performance. If the output data for your first two names is:

5 279

7 279

The output error is processed and the score cannot be scored.

Input format:

Contains n+1 lines:

The 1th act is a positive integer n, indicating the number of students enrolled in the school.

2nd to n+1, each line has 3 digits separated by a space, each of which is between 0 and 100. The 3 numbers in line J indicate the students ' grades in Chinese, maths and English in j-1. Each student's school number is numbered 1~n (the line number of the input data minus 1) according to the input order.

The data given are correct and do not have to be tested.

50% of the data to meet: Each student's overall scores are different;
100% of the data meet: 6<=n<=300.

Output format:

There are 5 lines, each line is two positive integers separated by a space, which in turn represents the first 5 students ' number and total score.

Sample input:
Example #1:690 67 8087 66 9178 89 9188 99 7767 89 6478 89 98 Example #2:880 89 89 88 98 7890 67 8087 66 9178 89 9188 99 7767 89 6478 89 98
Sample output:
Example #1:6 2654 2643 2582 2441 237 Sample #2:8 2652 2646 2641 2585 258

struct sort ... Have not learned the structure of the can go to learn, or will not understand.
On the code: Big guy do not look (believe that the big guy don't need me this super Konjac KONJAC code!!! )。。。


#include <bits/stdc++.h>using namespacestd;structstudent{intA,b,c; intSum,num;}; Student a[305];BOOLCMP (student a,student b) {returnA.sum>b.sum | | A.sum==b.sum && A.A&GT;B.A | | A.sum==b.sum && A.A==B.A && a.num<b.num;//The function is a little complicated, just follow the question .}intMain () {intN; CIN>>N;  for(intI=1; i<=n;i++) {cin>>a[i].a>>a[i].b>>a[i].c; A[i].sum=A[I].A+A[I].B+A[I].C;//according to the topic designa[i].num=i; } sort (A+1, a+n+1, CMP);//Recommended Sort!!! It's a lot easier .     for(intI=1; i<=5; i++) cout<<a[i].num<<" "<<a[i].sum<<Endl; return 0;}
View Code



Scholarship---Sort

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.