PAT a1075题解

120 篇文章 0 订阅
109 篇文章 0 订阅
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
const int maxn = 10010;

struct Student{
	int id;
	int score[6];
	bool flag;
	int score_all;
	int solve;
}stu[maxn];

int n, k, m;
int full[6];
bool cmp(Student a, Student b){
	if(a.score_all != b.score_all) return a.score_all > b.score_all;
	else if(a.solve != b.solve) return a.solve > b.solve;
	else return a.id < b.id;
} 

void init(){
	for(int i = 1; i <= n; i++){
		stu[i].id = i;
		stu[i].score_all = 0;
		stu[i].solve = 0;
		stu[i].flag = false;
		memset(stu[i].score, -1, sizeof(stu[i].score));
	}
}

int main(){
	scanf("%d%d%d", &n, &k, &m);
	init();
	for(int i = 1; i <= k; i++){
		scanf("%d", &full[i]);
	}
	int u_id, p_id, score_obtained;
	for(int i = 0; i < m; i++){
		scanf("%d%d%d", &u_id, &p_id, &score_obtained);
		if(score_obtained != -1){
			stu[u_id].flag = true;
		}
		if(score_obtained == -1 && stu[u_id].score[p_id] == -1){
			stu[u_id].score[p_id] = 0;
		}
		if(score_obtained == full[p_id] && stu[u_id].score[p_id] < full[p_id]){
			stu[u_id].solve++;
		}
		if(score_obtained > stu[u_id].score[p_id]){
			stu[u_id].score[p_id] = score_obtained;
		}
	} 
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= k; j++){
			if(stu[i].score[j] != -1){
				stu[i].score_all += stu[i].score[j];
			}
		}
	}
	sort(stu + 1, stu + n + 1, cmp);
	int r = 1;
	for(int i = 1; i <= n && stu[i].flag == true; i++){
		if(i > 1 && stu[i].score_all != stu[i - 1].score_all){
			r = i;
		}
		printf("%d %05d %d", r, stu[i].id, stu[i].score_all);
		for(int j = 1; j <= k; j++){
			if(stu[i].score[j] == -1){
				printf(" -");
			}
			else{
				printf(" %d", stu[i].score[j]);
			}
		}
		printf("\n");
	}
	return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值