1075 PAT Judge (25分)

很麻烦,花了一个小时,最后一个点过不去又找了很长时间错误,这种奇坑的阅读理解题看看就好

#include<iostream>
#include<vector>//从来没提交过题的人和没有一题通过编译的人不输出,但是通过编译即使全部为0依然要输出(否则最后一个测试点过不去)(算法笔记有一个样例,可以试试)
#include<algorithm>//如果要输入,没通过编译的题输出0,没提交过的题输出-
using namespace std;
const int maxn = 1e5 + 10;
int n, k, m, pro[6];
struct node {
	int id;
	int score[6], sum;
	int cnt, flag;
};
node stu[maxn];
int isHave[maxn] = { 0 };

void adj(int id) {
	stu[id].sum = stu[id].cnt = 0;
	for (int i = 1; i <= k; i++) {
		if (stu[id].score[i] == pro[i]) { stu[id].cnt++; }
		if (stu[id].score[i] != -1&& stu[id].score[i] != -2) {
			stu[id].sum += stu[id].score[i];
		}
	}
}
bool cmp(node a, node b) {
	if (a.sum != b.sum) { return a.sum > b.sum; }
	else {
		if (a.flag != b.flag) { return a.flag > b.flag; }
		else {
			if (a.cnt != b.cnt) { return a.cnt > b.cnt; }
			else { return a.id < b.id; }
		}
	}
}
int main() {
	scanf("%d%d%d", &n, &k, &m);
	for (int i = 1; i <= k; i++) { scanf("%d",&pro[i]); }
	int id, t, s;
	for (int i = 0; i < m; i++) {
		scanf("%d%d%d", &id, &t, &s);
		if (isHave[id] == 0) {
			stu[id] = { id,{-2,-2,-2,-2,-2,-2},0,0,0 };//-2代表没有提交过这道题
			stu[id].score[t] = s;
			isHave[id] = 1;
		}
		else { if (s > stu[id].score[t]) stu[id].score[t] = s; }
		if (s != -1) { stu[id].flag = 1; }//即有过通过编译的题,只要通过编译就输出
	}

	for (int i = 0; i < maxn; i++) { if (isHave[i]) adj(i); }
	sort(stu, stu + maxn, cmp);
	int rank = 1;
	printf("%d %05d %d", rank, stu[0].id, stu[0].sum);
	for (int i = 1; i <= k; i++) {
		if (stu[0].score[i] == -1) { printf(" 0"); }
		else if (stu[0].score[i] == -2) { printf(" -"); }
		else { printf(" %d", stu[0].score[i]); }
	}
	printf("\n");
	for (int i = 1; i < n; i++) {
		if (stu[i].flag == 0) { break; }
		if (stu[i].sum < stu[i - 1].sum) { rank = i + 1; }
		printf("%d %05d %d", rank, stu[i].id, stu[i].sum);
		for (int j = 1; j <= k; j++) {
			if (stu[i].score[j] == -2) { printf(" -"); }
			else if (stu[i].score[j] == -1) { printf(" 0"); }
			else { printf(" %d", stu[i].score[j]); }
		}
		printf("\n");
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值