Print the names and surnames of the students in descending order of their average score. Input data

First, the number of students n is given, then n lines, each of which contains a surname, a name and three numbers (grades in three subjects: mathematics, physics, computer science). The data in the line is separated by a single space. Ratings range from 1 to 5.

Output

It is necessary to print the surname-first name pairs one per line, separating the last name and the name by one space. Display estimates do not need. If several students have the same average scores, they should be displayed in the order specified in the input data.

Sample Input:

3 Markov Valeriy 5 5 5 Sergey Petrov 1 1 1 Petrov Petr 3 3 3 

Sample Output:

 Markov Valeriy Petrov Petr Sergey Petrov 

Closed due to the fact that off-topic participants sanmai , Harry , Nick Volynkin Jun 21 '17 at 4:39 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The message contains only the text of the task, in which there is no description of the problem, or the question is purely formal (" how do I do this task ") . To reopen the question, add a description of the specific problem, explain what does not work, what you see the problem. " - sanmai, Harry, Nick Volynkin
If the question can be reformulated according to the rules set out in the certificate , edit it .

    1 answer 1

    Since this is most likely a school problem, I did not bother with sorting and realized the usual bubble sorting.

     #include <iostream> using namespace std; struct student { string surname; string name; double avg; }; int main() { int n; cin >> n; student studs[n]; for (int i = 0; i < n; i++) { int m1, m2, m3; cin >> studs[i].surname >> studs[i].name; cin >> m1 >> m2 >> m3; studs[i].avg = (m1 + m2 + m3) / 3.0; } for (int i = 1; i < n; i++) { for (int j = 1; j < n; j++) { if (studs[i-1].avg < studs[i].avg) { student ex; ex = studs[i - 1]; studs[i - 1] = studs[i]; studs[i] = ex; } } } for (int i = 0; i < n; i++) { cout << studs[i].surname << " " << studs[i].name << "\n"; } return 0; } 

    The working example here is https://ideone.com/9F0XDf

    • Sorry, but this decision is wrong - Alone_Fox
    • A test system is used for verification and the program fails the test - Alone_Fox
    • @Alone_Fox on which test fails and with what error? - Ruslan Isaev
    • Not specified what is checked in the test - Alone_Fox
    • one
      @Alone_Fox, can I then link to the task and the testing system? - Ruslan Isaev