PAT甲级1062/乙级1015 德才论 (25分)

抓住了8月份的尾巴✨

#pragma warning(disable:4996)
#include
#include
#include
#include
using namespace std;

struct studentinfo {
     
	int id;
	int de;
	int cai;
	int sum;
	int figure;
}student[100010];

bool cmp(struct studentinfo a, struct studentinfo b)
{
     
	if (a.figure != b.figure)
		return a.figure < b.figure;
	else if (a.sum != b.sum)
		return a.sum > b.sum;
	else if (a.de != b.de)
		return a.de > b.de;
	else
		return a.id < b.id;
}

int main()
{
     
	int N, L, H;
	int n=0;
	scanf("%d%d%d", &N, &L, &H);
	for (int i = 0; i < N; i++)
	{
     
		scanf("%d%d%d", &student[i].id, &student[i].de, &student[i].cai);
		student[i].sum = student[i].cai + student[i].de;
		if (student[i].de < L || student[i].cai < L)
		{
     
			student[i].figure = 5;
			n--;
		}
		else if (student[i].de >= H && student[i].cai >= H)
		{
     
			student[i].figure = 1;
		}
		else if (student[i].de >= H && student[i].cai < H)
		{
     
			student[i].figure = 2;
		}
		else if (student[i].de < H && student[i].cai < H && student[i].cai <= student[i].de)
		{
     
			student[i].figure = 3;
		}
		else
		{
     
			student[i].figure = 4;
		}
		n++;
	}
	sort(student, student + N, cmp);
	printf("%d\n", n);
	for (int i = 0; i < N&&student[i].figure != 5; i++)
	{
     
		printf("%d %d %d\n", student[i].id, student[i].de, student[i].cai);
	}
}

你可能感兴趣的:(PAT)