只过了第一个点,问题出在冒泡排序,但是错哪了??

P5740 【深基7.例9】最厉害的学生

Aheaddd @ 2021-08-22 11:59:05

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
    struct student
    {
        string name;
        int score1;
        int score2;
        int score3;
        int sum = score1 + score2 + score3;
    };
    student stu[1010];

int main()
{
    int n, max = 0;
    cin >> n;
    for(int i=0;i<n;i++)
    {
        cin >> stu[i].name >> stu[i].score1 >> stu[i].score2 >> stu[i].score3;
    }
    for (int i = 0; i < n; i++)
    {

        if (stu[i].sum < stu[i + 1].sum)
        {
            struct student stu1= stu[i];
            stu[i] = stu[i + 1];
            stu[i + 1] = stu1;
        }
    }
    cout << stu[0].name << " " << stu[0].score1 << " " << stu[0].score2 << " " << stu[0].score3;
    return 0;

}

by 听取MLE声一片 @ 2021-08-22 12:14:21

这也不能算冒泡吧


上一页 |