PAT1075. PAT Judge (25)

其中在排名输出上参照了

http://blog.csdn.net/xyzchenzd/article/details/27074665,原先自己写的很繁琐,而且还有一个测试点不通过。

#include <iostream>
#include <vector>
#include <string.h>
#include <algorithm>
#include <stdio.h>
using namespace std;
struct PATInfo
{
	int userId;
	int p[10];
	int sum;
	int flag;// is qualified to output
	int perfect;// full score num
	PATInfo(){
		for(int j=0;j<10;j++) p[j]=-2;
		sum=0;
		flag=0;
		perfect=0;
	}
};
int n,k,m;
int i,j;
int prob[10];
bool cmp(const PATInfo &a,const PATInfo &b){
	if(a.sum!=b.sum) return a.sum>b.sum;
	if(a.perfect!=b.perfect) return a.perfect>b.perfect;
	return a.userId<b.userId;
}
int main()
{

	cin>>n>>k>>m;
	PATInfo *userSet=new PATInfo[n+1];
	for(i=1;i<=k;i++) cin>>prob[i];
	for(i=1;i<=n;i++) userSet[i].userId=i;
	int uId,pId,obtainS;
	for(i=0;i<m;i++){
		cin>>uId>>pId>>obtainS;
		if(userSet[uId].p[pId]<obtainS){
			if(obtainS>=0){
				userSet[uId].sum+=obtainS;
				userSet[uId].flag=1;
			}
			if(userSet[uId].p[pId]>0){
				userSet[uId].sum-=userSet[uId].p[pId];
			}
			userSet[uId].p[pId]=obtainS;
			if(obtainS==prob[pId]){
				userSet[uId].perfect++;
			}
		}
	}
	sort(userSet+1,userSet+n+1,cmp);
	int score=userSet[0].sum;
	int t=1;
	for(i=1;i<=n;i++){
		if(userSet[i].flag==0) break;
		if(score!=userSet[i].sum){
			t=i;
			score=userSet[i].sum;
		}
		printf("%d %05d ",t,userSet[i].userId);
		cout<<userSet[i].sum;
		for(j=1;j<=k;j++){
			if(userSet[i].p[j]==-2){
				cout<<" -";
			}else if(userSet[i].p[j]==-1){
				cout<<" 0";
			}else{
				cout<<" "<<userSet[i].p[j];
			}
		}
		cout<<endl;
	}
	delete [] userSet;
	return 0;
}

  

时间: 2024-08-02 05:28:24

PAT1075. PAT Judge (25)的相关文章

PAT 1075. PAT Judge (25)

题目地址:http://pat.zju.edu.cn/contests/pat-a-practise/1075 此题主要考察细节的处理,和对于题目要求的正确理解,另外就是相同的总分相同的排名的处理一定要熟练,还有就是编译没有通过为零分,没有提交显示为"-": #include <cstdio> #include <vector> #include <algorithm> using namespace std; const int NUM=10001

PTA 10-排序5 PAT Judge (25分)

题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/677 5-15 PAT Judge   (25分) The ranklist of PAT is generated from the status list, which shows the scores of the submissions. This time you are supposed to generate the ranklist for PAT. Input Spe

1075. PAT Judge (25)

题目如下: The ranklist of PAT is generated from the status list, which shows the scores of the submittions. This time you are supposed to generate the ranklist for PAT. Input Specification: Each input file contains one test case. For each case, the first

PAT(A) 1075. PAT Judge (25)

The ranklist of PAT is generated from the status list, which shows the scores of the submittions. This time you are supposed to generate the ranklist for PAT. Input Specification: Each input file contains one test case. For each case, the first line

PAT1075. PAT Judge

The ranklist of PAT is generated from the status list, which shows the scores of the submittions. This time you are supposed to generate the ranklist for PAT. Input Specification: Each input file contains one test case. For each case, the first line

PATA1075 PAT Judge (25 分)

The ranklist of PAT is generated from the status list, which shows the scores of the submissions. This time you are supposed to generate the ranklist for PAT. Input Specification: Each input file contains one test case. For each case, the first line

PTA 5-15 PAT Judge (25分)

/* * 1.主要就用了个sort对结构体的三级排序 */ #include "iostream" #include "algorithm" using namespace std; int perfectScore[6]; struct Node { int id; int score[6] = {-2,-2,-2,-2,-2,-2}; /* 记录每一题的分数 初始化为-2代表没答题 */ int totalScore = 0; /* 记录总分 */ int pe

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

相当于是模拟OJ评测,这里注意最后输出:1.那些所有提交结果都是-1的(即均未通过编译器的),或者从没有一次提交过的用户,不需要输出.2.提交结果为-1的题目,最后输出分数是03.某个题目从没有提交过的,输出'-' #include <iostream> #include <cstdio> #include <algorithm> #include <string.h> #include <cmath> #include <queue>

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

简单模拟题. 注意一点:如果一个人所有提交的代码都没编译通过,那么这个人不计排名. 如果一个人提交过的代码中有编译不通过的,也有通过的,那么那份编译不通过的记为0分. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<stack> #include<queue> #include<str