80分求调

P1093 [NOIP2007 普及组] 奖学金

SHC_CENSORED @ 2024-07-09 10:24:30

WA on #6#8

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
struct re{
    int Chinese,Math,English,Score;//语数英和总分 
    int num;//学号 
}a[1000];int n;
bool cmp(re x,re y){
    if(x.Score==y.Score){//总分相同比语文 
        if(x.Chinese>y.Chinese)return x.Chinese>y.Chinese;
        //语文大的放前面 
        return x.num<y.num;//语文相同比学号 学号小的放前面 
    }
    return x.Score>y.Score;//总分大的放前面 
}
signed main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i].Chinese>>a[i].Math>>a[i].English;
        a[i].Score=a[i].Chinese+a[i].Math+a[i].English;
        a[i].num=i;
    }
    sort(a+1,a+n+1,cmp);
    for(int i=1;i<=5;i++){
        cout<<a[i].num<<" "<<a[i].Score<<"\n";
    }
    return 0;
}

by 13146367338hk @ 2024-07-09 10:27:52

@yutiangaojubileizhen

#include<iostream>
#include<algorithm>
using namespace std;
struct stu
{
    int num;
    int c,m,e; 
    int sum;
}student[310];
bool cmp(stu a,stu b)
{
    if(a.sum>b.sum) return 1;
    else if(a.sum<b.sum) return 0;
    else
    {
        if(a.c>b.c) return 1;
        else if(a.c<b.c) return 0;
        else
        {
            if(a.num>b.num) return 0;
            else return 1;
        }
    }
}
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        student[i].num=i;
        cin>>student[i].c>>student[i].m>>student[i].e;
        student[i].sum=student[i].c+student[i].m+student[i].e;
    }
    sort(student+1,student+1+n,cmp);
    for(int i=1;i<=5;i++)
        cout<<student[i].num<<' '<<student[i].sum<<endl;
    return 0;
//求关注

by 13146367338hk @ 2024-07-09 10:28:20

@13146367338hk 求关注


by SHC_CENSORED @ 2024-07-09 10:29:03

谢谢!过了 已关注


|