PAT (Advanced Level) 1075——我愿称之为阅读理解

题目传送门

  • 成绩分为以下三种情况:
    • 正常提交,得分>=0
    • 编译失败,标识为-1,得分0,在输出时为0
    • 无提交,在输出时为-
  • 成绩排序规则:
    • 按照总成绩降序
    • 总成绩相同,按照AC数量降序
    • 总成绩和AC数量相同,按照id升序
  • 不参与排名的情况:
    • 无提交
    • 提交结果全部编译失败

题目有一个很隐晦的边界情况:
某个考生所有题目都通过了编译,但是都得了0分
这个学生也是要输出的,因为并没有违背“全场没有提交,或是没有能通过编译的提交”这个情况
他编译通过了,也提交了,只是都得了0分而已

注意排名计算公式:

//sc: 上一名的分数
//rk: 当前排名
if (stu[i].tot < sc) { sc = stu[i].tot; rk = i; }

我爱柳神😘

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

const int N = 10010;
int n, m, k;
int total_score[10];
struct node {
	int id;
	int score[10];
	int tot;
	int perfect;
};
node stu[N];

int cmp(const node &A,const node &B) {
	return (A.tot > B.tot) ||
		(A.tot == B.tot && A.perfect > B.perfect) ||
		(A.tot == B.tot && A.perfect == B.perfect && A.id < B.id);
}

int main()
{
	scanf("%d%d%d", &n, &k, &m);
	for (int i = 1; i <= n; ++i) {
		stu[i].id = i;
		stu[i].tot = 0;
		stu[i].perfect = 0;
		for (int j = 1; j <= k; ++j) stu[i].score[j] = -2;
	}
	for (int i = 1; i <= k; ++i) scanf("%d",&total_score[i]);
	for (int i = 1; i <= m; ++i) {
		int x, y, z;
		scanf("%d%d%d", &x, &y, &z);
		if (z > stu[x].score[y])
			stu[x].score[y] = z;
		// -2 never submit
		// -1 CE is considered as 0 when outputing
	}
	for (int i = 1; i <= n; ++i) {
		int f = 0;
		for (int j = 1; j <= k; ++j)
			if (stu[i].score[j] >= 0) {
				f = 1;
				stu[i].tot += stu[i].score[j];
				if (stu[i].score[j] == total_score[j])
					stu[i].perfect++;
			}
		if (!f) stu[i].tot = -1;
		//never submit or always CE
	}
	sort(stu + 1, stu + 1 + n, cmp);
	int rk = 1;
	int sc = stu[1].tot;
	for (int i = 1; i <= n; ++i) {
		if (stu[i].tot == -1) break;
		if (stu[i].tot < sc) { sc = stu[i].tot; rk = i; }
		printf("%d %05d %d", rk, stu[i].id, stu[i].tot);
		for (int j = 1; j <= k; ++j)
			if (stu[i].score[j] >= 0) printf(" %d", stu[i].score[j]);
			else if (stu[i].score[j] == -1) printf(" 0");
		    else printf(" -");
		printf("\n");
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值