求助啊求助 为什么90?

P1093 [NOIP2007 普及组] 奖学金

Aoteman45 @ 2021-03-22 22:00:47

求助求助 新手第一次发帖 请多指教啊 点9WA了??

#include<iostream>
using namespace std;
struct person
{
    int chinese;
    int english;
    int math;
    int num;
    int sum;
};
int main()
{
    person a[301];
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
        a[i].num = i;
        cin >> a[i].chinese;
        cin >> a[i].math;
        cin >> a[i].english;
        a[i].sum = a[i].chinese + a[i].math + a[i].english;
    }//输入
    person b;
    for (int j = 1; j <= n; ++j)
        for (int i = 1; i <= n; ++i)
            if (a[i].sum < a[i + 1].sum)
            {
                b = a[i];
                a[i] = a[i + 1];
                a[i + 1] = b;
            }
    for (int j = 1; j <= n; ++j)
        for (int i = 1; i <= n; ++i)
            if (a[i].sum == a[i + 1].sum)
            {
                if (a[i].chinese < a[i + 1].chinese)
                {
                    b = a[i];
                    a[i] = a[i + 1];
                    a[i + 1] = b;
                }
            }

    for (int j = 1; j <= n; ++j)
        for (int i = 1; i <= n; ++i)
            if (a[i].sum == a[i + 1].sum && a[i].chinese == a[i + 1].chinese)
                if (a[i].num > a[i].num)
                {
                    b = a[i];
                    a[i] = a[i + 1];
                    a[i + 1] = b;
                }
    for (int i = 1; i <= 5; ++i)
        cout << a[i].num << " " << a[i].sum << endl;
    return 0;
}

by Water_Cows @ 2021-03-22 23:01:07

数组写在 main 里面可不是一个好习惯哦~


by linyuhuai @ 2021-04-03 21:29:16

倒数第10行

if (a[i].num > a[i].num)

应该是

if (a[i].num > a[i+1].num)

|