1075 PAT Judge (25point(s)) Easy twice agin *一些细节问题

Posted songlinxuan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了1075 PAT Judge (25point(s)) Easy twice agin *一些细节问题相关的知识,希望对你有一定的参考价值。

基本思路:

还是简单的排序问题,但是需要注意的是一些基本的思路和细节点;

 

关键点:

1.关于开数组的问题,特别大的话尽量开常规数组,这样避免初始化时候resize不太方便;

2.关于结构体初始化,增加逻辑可读性,直接提出一个函数专门init;

3.注意题目的隐含条件,尤其是是否有重复输入的问题;

4.命名方式也要注意,以后改用帕斯卡命名法或者驼峰命名法;

5.关于rank序列计算,需要学习一下;

 

#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<vector> 
#include<string>
#include<math.h>
#include<algorithm>
#include<cstring>
using namespace std;
using std::vector;
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() {
	//k problems number;
	//m submission number;
	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("
");
	}
	system("pause");
	return 0;
}

  

以上是关于1075 PAT Judge (25point(s)) Easy twice agin *一些细节问题的主要内容,如果未能解决你的问题,请参考以下文章

1075. PAT Judge (25)

1075. PAT Judge (25)

PATA1075 PAT Judge (25 分)

PAT鐢茬骇 1075 PAT Judge (25鍒?

PAT甲题题解-1075. PAT Judge (25)-排序

PAT (Advanced Level) 1075. PAT Judge (25)