1075 PAT Judge (25分)

14 篇文章 0 订阅

在这里插入图片描述
在这里插入图片描述
常规思路,注意检查数组大小大于给出范围。

注意点:

  • 一题都没提交的、没有一个提交通过编译器的不进入排序
  • 没提交过的题目输出-,提交过得零分,或未通过编译器输出0

-2表示从未提交,用-1表示提交过但是没有通过编译器。

#include<algorithm>
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
struct node {
	int rank, id, fullmark = 0;
	vector<int> score;	//never submmit: -2 didn't pass: -1
	node() {
		score.resize(6);	//score[0] is total
		fill(score.begin(), score.end(), -2);	//-1-->never submit or do not pass the compiler
	}
}table[100010];
bool cmp(node a, node b) {
	if (a.score[0] != b.score[0]) {
		return a.score[0] > b.score[0];
	}
	else if (a.fullmark != b.fullmark) {
		return a.fullmark > b.fullmark;
	}
	else return a.id < b.id;
}
int main() {
	vector<int> marks;
	int numUser, numProblem, numSubmission;
	cin >> numUser >> numProblem >> numSubmission;
	marks.resize(numProblem + 1);
	for (int i = 1; i <= numProblem; i++) {
		cin >> marks[i];
	}
	for (int i = 0; i < numSubmission; i++) {
		int id, index, score;
		scanf("%d %d %d", &id, &index, &score);
		table[id].id = id;
		table[id].score[index] = max(table[id].score[index], score);	//-2 --> -1
	}
	vector<node> billboard;
	for (int i = 1; i <= numUser; i++) {
		//calculate total
		int total = 0;
		bool hasSolution = false;
		for (int j = 1; j <= numProblem; j++) {
			if (table[i].score[j] >= 0) {
				hasSolution = true;
				total += table[i].score[j];
				if (table[i].score[j] == marks[j]) {
					table[i].fullmark++;
				}
			}
		}
		if (hasSolution) {
			table[i].score[0] = total;
			billboard.push_back(table[i]);
		}
	}
	sort(billboard.begin(), billboard.end(), cmp);
	billboard[0].rank = 1;
	for (int i = 1; i < billboard.size(); i++) {
		if (billboard[i].score[0] == billboard[i - 1].score[0]) {
			billboard[i].rank = billboard[i - 1].rank;
		}
		else billboard[i].rank = i + 1;
	}
	for (auto e : billboard) {
		printf("%d %05d %d", e.rank, e.id, e.score[0]);
		for (int i = 1; i <= numProblem;i++) {
			if (e.score[i] >= 0) {
				printf(" %d", e.score[i]);
			}
			else if (e.score[i] == -1) {
				printf(" 0");
			}
			else printf(" -");	// -2
		}
		printf("\n");
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值