70分求助

P1093 [NOIP2007 普及组] 奖学金

LLEeeeEe @ 2024-02-20 15:08:02

第 6 7 8 检查点没通过 求大佬们帮忙 我不知道我错哪了 谢谢

#include<iostream>
#include<set>
using namespace std;

class student
{
  public:
   student(int a,int b,int c,int d,int e)
   {
    aa = a;
    bb = b;
    cc = c;
    dd = d;
    ee = e;
   }
   int aa,bb,cc,dd,ee;

};

class studentf
{
 public:
 bool operator()(const student &s1,const student &s2)
 {
    if(s1.aa != s2.aa)
    return s1.aa > s2.aa;
    if(s1.aa == s2.aa)
    return s1.ee < s2.ee; 

 }
};

int main()
{
 set<student,studentf> s;
 set<student,studentf>:: iterator it;
 int n,i,z,x,y;
 scanf("%d",&n);
 for(i = 1; i <= n; i++)
 {
  scanf("%d %d %d",&z,&x,&y);   
  s.insert(student(z+x+y,z,x,y,i));
 }

 for( i=0,it = s.begin(); it != s.end(); it++,i++)
 {
    if( i<5 )
    cout << it -> ee<<" "<< it -> aa <<" "<<endl;

 }
 return 0;  
}

by Administrator2023 @ 2024-03-13 17:23:46

AC CODE

#include <bits/stdc++.h>
using namespace std;
const int M = 3e2 + 10;

int n;
struct NODE {
    int id, chi, math, eng, sum;
} infor[M];

bool cmp(NODE x, NODE y) {
    if(x.sum == y.sum) {
        if(x.chi != y.chi) return x.chi > y.chi;
        else return x.id < y.id;
    }
    return x.sum > y.sum;
}
int main() {
    cin >> n;
    for(int i = 0; i < n; ++i) {
        cin >> infor[i].chi >> infor[i].math >> infor[i].eng;
        infor[i].id = i + 1;
        infor[i].sum = infor[i].chi + infor[i].math + infor[i].eng;
    }
    sort(infor, infor + n, cmp);
    for(int i = 0; i < 5; ++i) {
        cout << infor[i].id << " " << infor[i].sum << endl;
    }
    return 0;
}

by TODAYS @ 2024-03-31 21:23:59

AC代码```cpp

include <bits/stdc++.h>

using namespace std;

struct student { int yu; int shu; int ying; int zong; int i; }si[305];

bool cmp(student a,student b) { a.zong=a.yu+a.shu+a.ying; b.zong=b.yu+b.shu+b.ying; if(a.zong==b.zong) { if(a.yu!=b.yu) { return a.yu>b.yu; } else { return a.i<b.i; } } return a.zong>b.zong; }

int main() { int n; cin >>n; for(int i=1;i<=n;i++) { cin >>si[i].yu>>si[i].shu>>si[i].ying; si[i].i=i; } sort(si+1,si+n+1,cmp); for(int i=1;i<=5;i++) { cout <<si[i].i<<" "<<si[i].yu+si[i].shu+si[i].ying<<endl; } return 0; }


by TODAYS @ 2024-03-31 21:24:47

@efdfw Ac代码

#include <bits/stdc++.h>
using namespace std;

struct student
{
    int yu;
    int shu;
    int ying;
    int zong;
    int i;
}si[305];

bool cmp(student a,student b)
{
    a.zong=a.yu+a.shu+a.ying;
    b.zong=b.yu+b.shu+b.ying;
    if(a.zong==b.zong)
    {
        if(a.yu!=b.yu)
        {
            return a.yu>b.yu;
        }
        else 
        {
            return a.i<b.i;
        }
    }
    return a.zong>b.zong;
}

int main()
{
    int n;
    cin >>n;
    for(int i=1;i<=n;i++)
    {
        cin >>si[i].yu>>si[i].shu>>si[i].ying;
        si[i].i=i;
    }
    sort(si+1,si+n+1,cmp);
    for(int i=1;i<=5;i++)
    {
        cout <<si[i].i<<" "<<si[i].yu+si[i].shu+si[i].ying<<endl;
    }
    return 0;
}

|