PTA甲级考试真题练习75——1075 PAT Judge

题目

在这里插入图片描述

思路

排序题

坑点

如果遇到满分重复提交的情况不入满分数,所以不应该在输入的时候计算满分数,而是应该在计算总分数的时候计算满分数

代码

#include <iostream>
#include<algorithm>
using namespace std;
#define nmax 10005
#define inf 999999
#define pmax 6
int full[pmax];
struct Info
{
	int _index;
	int sum;
	int ID;
	int problem[pmax];
	int fullnum;
}info[nmax];
bool cmp(const Info& a, const Info& b) {
	if (a.sum != b.sum)
		return a.sum > b.sum;
	else
		if (a.fullnum != b.fullnum)
			return a.fullnum > b.fullnum;
		else
			return a.ID < b.ID;
}
int main()
{
	int pn, qn, n;
	cin >> pn >> qn >> n;
	for (int i = 1; i <= qn; ++i)  
		cin >> full[i];
	for (int i = 0; i < nmax; ++i) {
		for (int j = 0; j < pmax; ++j) {
			info[i].problem[j] = -2;
		}
		info[i].fullnum = 0;
		info[i].sum = 0;
	}
	for (int i = 0; i < n; ++i) {
		int ID,_index,tmp;
		cin >> ID >> _index >> tmp;
		info[ID].problem[_index] = max(info[ID].problem[_index], tmp);
		info[ID].ID = ID;
	}
	for (int i = 1; i <= pn; ++i) {
		int noMark = true;
		for (int j = 1; j <= qn; ++j) {
			if (info[i].problem[j] != -1 && info[i].problem[j] != -2) {
				noMark = false;
				if (info[i].problem[j] == full[j])
					info[i].fullnum++;
				info[i].sum += info[i].problem[j];
			}
		}
		//没有成绩就退出
		if (noMark)
			info[i].sum = -10;
	}
	sort(info + 1, info + 1 + pn, cmp);
	for (int i = 1; i <= pn; ++i) {
		if (info[i].sum == -10)
			break;
		if (i != 1 && info[i].sum == info[i - 1].sum)
			info[i]._index = info[i - 1]._index;
		else
			info[i]._index = i;
		printf("%d %05d %d", info[i]._index,info[i].ID, info[i].sum);
		for (int j = 1; j <= qn; ++j) {
			if (info[i].problem[j] != -1 && info[i].problem[j] != -2)
				cout << " " << info[i].problem[j];
			else if (info[i].problem[j] == -1)
				cout << " 0";
			else
				cout << " -";
		}
		cout << endl;
	}
	return 0;
}

发布了153 篇原创文章 · 获赞 4 · 访问量 3799

猜你喜欢

转载自blog.csdn.net/qq_43647628/article/details/105307378
今日推荐