Little Monkey Programming C++ | Rating

Learn C++ from a young age! Record the questions in the learning process of Xueersi Monkey programming and record every moment. Any infringement will be deleted immediately, thank you for your support!

Attached is a summary post: Little Monkey Programming C++ | Summary-CSDN Blog


[Title description]

The little monkey is watching the diving competition.

There are  n  players coming to participate in the diving competition and there are  m  judges. After each competitor dives, each judge will give his or her score. In order to be as fair and objective as possible, each contestant's score is the average of the remaining scores after removing the maximum and minimum values ​​(if there are multiple maximum/minimum values, only one is removed) from the scores given by all judges.

The player with the highest score at the end wins first place, the player with the second highest score wins second place, and so on. However, there may be a tie of points. In this case, the monkey will default to the player with the smaller number being ranked higher. That is, if player No. 3 and player No. 5 both score 70, then the monkey will think that player No. 3 is ranked higher than player No. 5.

Now that the little monkey knows the scores of all the judges for all the players, he wants you to help him calculate the ranking list of the players, that is, for 1 ≤ i ≤ n , calculate the   number of the i -th player.

【enter】

The two integers  n and m in the first line represent the number of players and the number of judges respectively.

The next  n lines contain m  integers   in each line  . The j-  th integer  ai  in  the i- th line  represents   the score given by the j-th judge after the i-th player dives. The number of each player is 1~ in the order of  input  . n .

【Output】

Output a line  of n  integers. The  i  -th integer represents   the number of the player ranked i .

【Input sample】

4 4
4 70 69 34
18 43 85 71
100 50 69 80
67 82 90 43

【Output sample】

3 4 2 1

[Detailed code explanation]

#include <bits/stdc++.h>
using namespace std;
struct Stu {
    int s, id;
}a[2010];
bool cmp(Stu x, Stu y)
{
    if (x.s != y.s) return x.s>y.s;
    return x.id<y.id;
}
int main()
{
    int n, m;
    cin >> n >> m;
    for (int i=1; i<=n; i++) {
        a[i].id = i;
        int sum=0, maxn=0, minn=100;
        for (int j=1; j<=m; j++) {
            int score;
            cin >> score;
            maxn = max(maxn, score);
            minn = min(minn, score);
            sum += score;
        }
        a[i].s = sum - maxn - minn;
    }
    sort(a+1, a+n+1, cmp);
    for (int i=1; i<=n; i++) {
        cout << a[i].id << " ";
    }
    return 0;
}

【operation result】

4 4
4 70 69 34
18 43 85 71
100 50 69 80
67 82 90 43
3 4 2 1

Guess you like

Origin blog.csdn.net/guolianggsta/article/details/133914664