P1093 scholarship, p1093 Scholarship

Source: Internet
Author: User

P1093 scholarship, p1093 Scholarship
Description

A primary school has recently received a sponsorship program and plans to offer some of them the top five Student Development Scholarships with excellent academic performance. At the end of the course, each student has three course scores: Chinese, mathematics, and English. First, the total score is sorted from high to low. If the total score of the two students is the same, then the total score is sorted by the Chinese score from high to low. If both students have the same total score and Chinese score, therefore, students with small student numbers should be listed first. In this way, the sorting of each student is uniquely determined.

Task: calculate the total score based on the scores of the input three courses, sort the Scores according to the above rules, and output the student ID and total score of the top five students in the ranking order. Note: among the top five students, each has a different scholarship. Therefore, you must strictly follow the above rules. For example, in a correct answer, if the output data of the first two rows (two numbers for each row: Student ID and total score) is:

7 279 5 279 the meaning of the two rows is: the two students with the highest total score have their student IDs 7 and 5 in sequence. The total score of these two students is 279 (the total score is equal to the sum of the scores of the Chinese, mathematics, and English subjects), but the score of the students whose student ID is 7 is higher. If your first two output data are:

5 279 7 279 is handled according to the output error and cannot be scored.

Input/Output Format Input Format:

The input file scholar. in contains n + 1 rows:

1st act as a positive integer n, no more than 300, indicating the number of students participating in the selection.

The rows from 2nd to n + 1 have three numbers separated by spaces, each of which is between 0 and 100. The three numbers in row j represent the Chinese, maths, and English scores of students whose student ID is J-1. The student ID is 1 ~ N (the row number of the input data minus 1 ).

The given data is correct and does not need to be tested.

// Thanks to Huang xiaou for correcting the input format

Output Format:

There are 5 rows in the output file, each of which is two positive integers separated by spaces, indicating the student ID and total score of the first five students in turn.

Input and Output sample Input example #1:
[Input Example 1] 690 67 8087 66 9178 89 9188 99 7767 89 6478 89 880 98 [input Example 2] 8988 89 7890 98 8087 67 9178 66 9188 89 7767 99 6478 89 89 98
Output sample #1:
[Output Example 1] 6 2654 2643 2582 2441 237 2652 [Output Example 2] 8 2646 2641 2585 258
 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 struct node 7 { 8     int yuwen; 9     int shuxue;10     int yingyu;11     int bianhao;12     int zongfen;13 }a[301];14 int comp(const node &a ,const node & b)15 {16     if(a.zongfen!=b.zongfen)17     return a.zongfen>b.zongfen;18     if(a.yuwen!=b.yuwen)19     return a.yuwen>b.yuwen;20     else21     return a.bianhao<b.bianhao;22 }23 24 int main()25 {26     int n;27     scanf("%d",&n);28     for(int i=1;i<=n;i++)29     {30         scanf("%d%d%d",&a[i].yuwen,&a[i].shuxue,&a[i].yingyu);31         a[i].bianhao=i;32         a[i].zongfen=a[i].yuwen+a[i].shuxue+a[i].yingyu;33     }34     sort(a+1,a+n+1,comp);35     for(int i=1;i<=5;i++)36     {37         printf("%d %d\n",a[i].bianhao,a[i].zongfen);38     }39     return 0;40 }

 

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.