[Is this the legendary multi-Keyword sorting?] Scholarship

Source: Internet
Author: User

[Description]

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 three courses entered, sort by 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 data in these two rows indicates that the student IDs of the two students with the highest total score are 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
The error is handled according to the output and cannot be scored.

[Input format]

Input n + 1 rows:
1st act as a positive integer N, indicating the number of students selected by the school.
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.

[Output format]

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

[Example 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

[Analysis]

UpperCodeNot explained.

# Include <stdio. h> # include <stdlib. h> # define maxn 400 struct node {int Yu, Shu, Wai, Zong, num;} A [maxn]; int N; int CMP (const void *, const void * B) {node c = * (node *) A, D = * (node *) B; If (C. zong> D. zong) Return-1; if (C. zong <D. zong) return 1; if (C. yu> D. yu) Return-1; if (C. yu <D. yu) return 1; if (C. num <D. num) Return-1; if (C. num> D. num) return 1; return 0;} int main () {scanf ("% d", & N); For (INT I = 0; I <n; ++ I) {scanf ("% d", & A [I]. yu, & A [I]. shu, & A [I]. wai); A [I]. num = I + 1; A [I]. zong = A [I]. yu + A [I]. shu + A [I]. wai;} qsort (A, N, sizeof (node), CMP); For (INT I = 0; I <5; ++ I) printf ("% d \ n", a [I]. num, a [I]. zong); Return 0 ;}

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.