PAT甲级 1075 PAT Judge (25分)

//注意:排序的是满分解题数,而不是解题数。
#include <cstdio>
#include <cstring> #include <iostream> #include <algorithm> using namespace std; const int maxn = 200005; typedef long long ll; struct st{ int num,k[6],total_grade,total_q,order,t;//t代表解决题数,total_q代表完美解题数 }s[100005]; bool cmp(st p,st q) {//排序 if(p.total_grade != q.total_grade) return p.total_grade > q.total_grade; else if(p.total_q != q.total_q) return p.total_q > q.total_q; else return p.num < q.num; } int main() { int n,k,kk[6],m; scanf("%d%d%d",&n,&k,&m); for(int i = 1; i <= k; i++) scanf("%d",&kk[i]);//每科满分 int sno,num,grade; for(int i = 1; i <= n; i++) { s[i].num = i; s[i].total_grade = 0; s[i].total_q = 0; s[i].t = -1; memset(s[i].k,-1,sizeof(s[i].k)); } for(int i = 1; i <= m; i++) { scanf("%d%d%d",&sno,&num,&grade); if(grade >=0 ) { s[sno].t = 1; } else grade = 0; s[sno].k[num] = max(s[sno].k[num],grade); } for(int i = 1; i <= n; i++) { for(int j = 1; j <= k; j++) { if(s[i].k[j] != -1) s[i].total_grade += s[i].k[j]; if(s[i].k[j] ==kk[j]) s[i].total_q++; } } sort(s+1,s+1+n,cmp); for(int i = 1; i <= n; i++) { if(s[i].total_grade == s[i-1].total_grade) s[i].order = s[i-1].order; else s[i].order = i; } /*for(int i = 1; i <= n; i++) printf("%d ",s[i].t); printf("\n");*/ for(int i = 1; i <= n; i++) { if(s[i].t == 1) { printf("%d %05d %d",s[i].order,s[i].num,s[i].total_grade); for(int j = 1; j <= k; j++) { if(s[i].k[j] == -1) printf(" -"); else printf(" %d",s[i].k[j]); } printf("\n"); } } return 0; }

 

上一篇:PAT 乙级 1032 挖掘机技术哪家强


下一篇:闰年判断