1015 德才论

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
运行超时!!!!!!!

#include <iostream>

#include<algorithm>
using namespace std;
struct Chengji
{
    int number;
    int de;
    int cai;
    int score;
};
bool cmp(Chengji a, Chengji b)
{
    if(a.score == b.score)
    {
        if(a.de == b.de)
            return a.number<b.number;
        return a.de>b.de;
    }
    return a.score>b.score;
}
int main()
{
    int N,L,H;
    cin>>N>>L>>H;
    Chengji chengji[N];
    Chengji t1[N],t2[N],t3[N],t4[N];
    int p1=0,p2=0,p3=0,p4=0;
    int counter=0;
    for(int i=0;i<N;i++)
    {
        cin>>chengji[i].number>>chengji[i].de>>chengji[i].cai;
        chengji[i].score=chengji[i].de+chengji[i].cai;
        if(chengji[i].de>=L&&chengji[i].cai>=L)
        {
            counter++;
        }
    }
    cout<<counter<<endl;
    sort(chengji,chengji+N,cmp);
    for(int j1=0;j1<N;j1++)
    {
        if(chengji[j1].de>=H&&chengji[j1].cai>=H)
        {
            t1[p1++]=chengji[j1];
        }
        if(chengji[j1].de>=H&&chengji[j1].cai>=L&&chengji[j1].cai<H)
        {
            t2[p2++]=chengji[j1];
        }
        if(chengji[j1].de<H&&chengji[j1].de>=chengji[j1].cai&&chengji[j1].cai>=L)
        {
            t3[p3++]=chengji[j1];
        }
        if(chengji[j1].de<H&&chengji[j1].de<chengji[j1].cai&&chengji[j1].de>=L)
        {
           t4[p4++]=chengji[j1];
        }
    }
    for(int j2=0;j2<p1;j2++)
    {
        cout<<t1[j2].number<<" "<<t1[j2].de<<" "<<t1[j2].cai<<endl;
    }
    for(int j3=0;j3<p2;j3++)
    {
        cout<<t2[j3].number<<" "<<t2[j3].de<<" "<<t2[j3].cai<<endl;
    }
    for(int j4=0;j4<p3;j4++)
    {
        cout<<t3[j4].number<<" "<<t3[j4].de<<" "<<t3[j4].cai<<endl;
    }
    for(int j5=0;j5<p4;j5++)
    {
        cout<<t4[j5].number<<" "<<t4[j5].de<<" "<<t4[j5].cai<<endl;
    }
    return 0;
}

参考的别人的

#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
struct info{
    char num[10];
    int de_s,cai_s,sum;
    int clas;//类别
}stu[100010];
bool cmp(info a,info b)
{
    if(a.clas != b.clas) return a.clas < b.clas;
    else if(a.sum != b.sum) return a.sum > b.sum;
    else if(a.de_s != b.de_s) return a.de_s > b.de_s;
    else return strcmp(a.num,b.num) < 0;
}
int main(){
    int N,L,H;
    cin>>N>>L>>H;
    int cnt = N;
    for(int i = 0;i < N; i++)
    {
        cin>>stu[i].num>>stu[i].de_s>>stu[i].cai_s;
        stu[i].sum = stu[i].de_s + stu[i].cai_s;
        if(stu[i].de_s < L || stu[i].cai_s < L)
        {
            stu[i].clas = 5;
            cnt--;//及格人数减少1
        }
        else if(stu[i].de_s >= H && stu[i].cai_s >= H) stu[i].clas = 1;
        else if(stu[i].de_s >= H && stu[i].cai_s < H) stu[i].clas = 2;
        else if(stu[i].de_s < H && stu[i].cai_s < H && stu[i].de_s >= stu[i].cai_s) stu[i].clas = 3;
        else stu[i].clas = 4;
    }
    sort(stu,stu+N,cmp);
    cout<<cnt<<endl;
    for(int i = 0;i < cnt; i++)
    {
        cout<<stu[i].num<<" "<<stu[i].de_s<<" "<<stu[i].cai_s<<endl;
    }

    return 0;
 }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值