蒟蒻求助,哪里错了

P1093 [NOIP2007 普及组] 奖学金

Azure_Flame @ 2021-12-27 11:52:41

#include <bits/stdc++.h>
using namespace std;
int n;
struct student
{
    int name,chi,ma,en,sc;
}f[400];
bool cmp(int a,int b)
{
    return a>b;
}
void check()
{
    for(int i=1;i<=n;i++) f[i].sc=f[i].chi+f[i].ma+f[i].en;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
      cin>>f[i].chi>>f[i].ma>>f[i].en;
      f[i].name=i;
    } 
    check();
    sort(f+1,f+1+n,cmp);
    for(int i=1;i<=5;i++){
      if(f[i].sc==f[i+1].sc)
      {
        if(f[i].chi>f[i+1].chi){
          cout<<f[i].name<<" "<<f[i].sc<<endl;
          continue;
    }
        if(f[i].chi<f[i+1].chi)
        {
            swap(f[i].name,f[i+1].name);
            swap(f[i].sc,f[i+1].sc);
            cout<<f[i].name<<" "<<f[i].sc;
            continue;
        }
        if(f[i].chi==f[i+1].chi)
        {
            if(f[i].name<f[i+1].name)
            {
               cout<<f[i].name<<" "<<f[i].sc<<endl;
               continue;
        }
            if(f[i].name>f[i+1].name)
            {
              swap(f[i].name,f[i+1].name);
              swap(f[i].sc,f[i+1].sc);
              cout<<f[i].name<<" "<<f[i].sc;
              continue;
            }
        }
      }
}
    return 0;
}

by fyder_anran @ 2022-01-08 15:40:22

参考题解本人题解


|