PAT 乙级 1015 德才论

/*
	先分析题目,总共有四个等级,为了方便排序我根据不同等级增加了初始分。
	使用了qsort快速排序。
	不能使用cout,否则会超时。
*/
#include <stdio.h>
#include <stdlib.h>

using namespace std;

typedef struct Stu{
	int userID;
	int de_score;
	int cai_score;
	int total;
}Stu;

Stu stu_arr[100000];

int comp(const void *a,const void *b);

int main()
{
	int number,Low,High;
	scanf("%d%d%d",&number,&Low,&High);
	for(int i = 0;i<number;i++)
	{
		scanf("%d%d%d",&stu_arr[i].userID,&stu_arr[i].de_score,&stu_arr[i].cai_score);
		stu_arr[i].total = 0;
	}
	
	// Divide grade
	for(int i = 0; i<number;i++)
	{
		// Grade A 
		if(stu_arr[i].de_score>=High && stu_arr[i].cai_score>=High)
			stu_arr[i].total = 3000 + stu_arr[i].de_score + stu_arr[i].cai_score;
		// Grade B
		else if(stu_arr[i].de_score>=High && stu_arr[i].cai_score>=Low && stu_arr[i].cai_score<High )
			stu_arr[i].total = 2000 + stu_arr[i].de_score + stu_arr[i].cai_score;
		// Grade C
		else if(stu_arr[i].de_score>=Low && stu_arr[i].de_score<High && stu_arr[i].cai_score>=Low && stu_arr[i].cai_score<High && stu_arr[i].de_score>=stu_arr[i].cai_score)
			stu_arr[i].total = 1000 + stu_arr[i].de_score + stu_arr[i].cai_score;
		// Grade D
		else if(stu_arr[i].de_score>=Low && stu_arr[i].cai_score>=Low)
			stu_arr[i].total = stu_arr[i].de_score + stu_arr[i].cai_score;
	}
	
	// AC counts
	int counts = 0;
	for(int i = 0; i<number;i++)
		if(stu_arr[i].de_score>=Low && stu_arr[i].cai_score>=Low)
			counts ++;
	
	qsort(stu_arr,number,sizeof(Stu),comp);
	
	// OUTPUT 
	printf("%d\n",counts);
	int i = 0;
	while(stu_arr[i].de_score>=Low && stu_arr[i].cai_score>=Low)
	{
		printf("%d %d %d\n",stu_arr[i].userID,stu_arr[i].de_score,stu_arr[i].cai_score);
		i++;
	}
	
	return 0;
}

int comp(const void *a,const void *b)
{
	Stu s1 = *(Stu*)a;
	Stu s2 = *(Stu*)b;
	if(s1.total != s2.total)
		return s2.total - s1.total;
	else if(s1.de_score != s2.de_score)
		return s2.de_score - s1.de_score;
	else 
		return s1.userID - s2.userID;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值