标签:iss submit ble user nbsp 注意 输出 for int
相当于是模拟OJ评测,这里注意最后输出:
1.那些所有提交结果都是-1的(即均未通过编译器的),或者从没有一次提交过的用户,不需要输出。
2.提交结果为-1的题目,最后输出分数是0
3.某个题目从没有提交过的,输出‘-‘
#include <iostream> #include <cstdio> #include <algorithm> #include <string.h> #include <cmath> #include <queue> #define INF 0x3f3f3f3f using namespace std; const int maxn=10000+5; int problem[6]; struct User{ int id; int score=0; int problem[6]={-1,-1,-1,-1,-1,-1}; int submitted[6]={0,0,0,0,0,0}; //标记题目是否有提交,没提交的对应的就要输出‘-‘ int perfect=0; //拿满分的题目个数 int ranks=INF; int isShow=0; //用于标记是否要输出,即用户只要有一题通过编译器,不管是否为0,设置为1. bool operator<(const User tmp)const{ if(ranks==tmp.ranks){ if(perfect==tmp.perfect){ return id<tmp.id; } else{ return perfect>tmp.perfect; } } else{ return ranks<tmp.ranks; } } }user[maxn]; bool cmp1(User a, User b){ return a.score>b.score; } bool cmp2(User a,User b){ if(a.ranks==b.ranks){ if(a.perfect==b.perfect){ return a.id<b.id; } else{ return a.perfect>b.perfect; } } else{ return a.ranks<b.ranks; } } int main() { int N,K,M; int id,pid,score; scanf("%d %d %d",&N,&K,&M); for(int i=1;i<=K;i++){ scanf("%d",&problem[i]); } for(int i=0;i<M;i++){ scanf("%d %d %d",&id,&pid,&score); user[id].id=id; user[id].problem[pid]=max(user[id].problem[pid],score); user[id].submitted[pid]=1; //if(score==problem[pid]) // user[id].perfect++; //不能这里就统计拿满分的题目个数,因为可能存在多次提交 if(score!=-1) user[id].isShow=1; } for(int i=1;i<=N;i++){ for(int j=1;j<=K;j++){ if(user[i].problem[j]!=-1) user[i].score+=user[i].problem[j]; if(user[i].problem[j]==problem[j]) user[i].perfect++; } } sort(user+1,user+N+1,cmp1); int cnt=0; int lastid=0; user[0].ranks=cnt; user[0].score=-1; for(int i=1;i<=N;i++){ user[i].ranks=i; if(i!=1 && user[i].score==user[i-1].score) user[i].ranks=user[i-1].ranks; } sort(user+1,user+N+1,cmp2); for(int i=1;i<=N;i++){ if(user[i].isShow==0) continue; printf("%d %05d %d",user[i].ranks,user[i].id,user[i].score); for(int j=1;j<=K;j++){ if(user[i].submitted[j]==0){ printf(" -"); } else{ if(user[i].problem[j]!=-1) printf(" %d",user[i].problem[j]); else printf(" 0"); } } printf("\n"); } return 0; }
PAT甲题题解-1075. PAT Judge (25)-排序
标签:iss submit ble user nbsp 注意 输出 for int
原文地址:http://www.cnblogs.com/chenxiwenruo/p/6390646.html