sort 的初步应用,注意分类讨论,标志位
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
struct Stu
{
char id[15]={0};
int d=0,c=0;
int flag=99;// 1 2 3 4
//int r=0;//名次
}stu[101000];
bool cmp1(Stu a,Stu b)
{
if(a.flag==b.flag)
{
if(a.d+a.c==b.d+b.c)
{
if(a.d==b.d) return strcmp(a.id,b.id)<0;
else return a.d>b.d;
}
else return a.d+a.c>b.d+b.c;
}
else return a.flag<b.flag;
}
int main()
{
//可以先将考生划分类别再进行排序
int n=0,l=0,h=0;
int num=0;//不合格总人数
cin>>n>>l>>h;
for(int i=0;i<n;i++)
{
cin>>stu[i].id>>stu[i].d>>stu[i].c;
if(stu[i].d>=h&&stu[i].c>=h) stu[i].flag=1;
else if(stu[i].d>=h&&stu[i].c<h&&stu[i].c>=l) stu[i].flag=2;
else if(stu[i].c>=l&&stu[i].d>=stu[i].c) stu[i].flag=3;
else if(stu[i].c>=l&&stu[i].d>=l)stu[i].flag=4;
else num++;
}
sort(&stu[0],&stu[n],cmp1);//cmp函数返回bool型
cout<<n-num<<endl;
for(int i=0;i<n-num;i++)
{
cout<<stu[i].id<<" "<<stu[i].d<<" "<<stu[i].c<<endl;
}
}