pta A 1062 Talent and Virtue

大致思路:对于读入的数据,进行学生分类并存储在结构体中,然后进行多标尺的排序,第一标尺是学生类别,第二标尺是学生的总成绩,第三标尺是学生的道德成绩,最后是学号的字典序
本题的关键是结构体的设计和cmp函数的编写,结构体中用flag标志进行学生类别的区分
属于典型的排序题

#include<cstdio>
#include<cmath>
#include<vector>
#include<algorithm>
#include<string>
#include<cstring>
#include<iostream>
#define maxn 1000
using namespace std;
struct stu
{
    int d;
    int c;
    string num;
    stu(int d,int c,string t):d(d),c(c),num(t){}
    int flag;
};
vector<stu>s;
bool cmp(stu a,stu b)
{
    if(a.flag!=b.flag){
        return a.flag<b.flag;
    }
    if(a.c+a.d!=b.c+b.d){
        return a.c+a.d>b.c+b.d;
    }
    if(a.d!=b.d){
        return a.d>b.d;
    }
    return a.num<b.num;
}
int n;
int main()
{
    scanf("%d",&n);
    int up,low;
    scanf("%d %d",&low,&up);
    while(n--){
        string temp;
        int d,c;
        cin>>temp;
        scanf("%d %d",&d,&c);
        stu t(d,c,temp);
        if(d>=up&&c>=up){
            t.flag=1;
        }
        else if(d>=up&&c<up){
            t.flag=2;
        }
        else if(d>=c){
            t.flag=3;
        }
        else{
            t.flag=4;
        }
        if(d<low||c<low){
            continue;
        }
        s.push_back(t);
    }
    sort(s.begin(),s.end(),cmp);
    printf("%d\n",s.size());
    for(stu x:s){
        cout<<x.num;
        printf(" %d %d\n",x.d,x.c);
    }
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值