相当于是模拟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=+;
int problem[]; struct User{
int id;
int score=;
int problem[]={-,-,-,-,-,-};
int submitted[]={,,,,,}; //标记题目是否有提交,没提交的对应的就要输出'-'
int perfect=; //拿满分的题目个数
int ranks=INF;
int isShow=; //用于标记是否要输出,即用户只要有一题通过编译器,不管是否为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=;i<=K;i++){
scanf("%d",&problem[i]);
}
for(int i=;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]=;
//if(score==problem[pid])
// user[id].perfect++; //不能这里就统计拿满分的题目个数,因为可能存在多次提交
if(score!=-)
user[id].isShow=;
}
for(int i=;i<=N;i++){
for(int j=;j<=K;j++){
if(user[i].problem[j]!=-)
user[i].score+=user[i].problem[j];
if(user[i].problem[j]==problem[j])
user[i].perfect++;
}
}
sort(user+,user+N+,cmp1); int cnt=;
int lastid=;
user[].ranks=cnt;
user[].score=-;
for(int i=;i<=N;i++){
user[i].ranks=i;
if(i!= && user[i].score==user[i-].score)
user[i].ranks=user[i-].ranks;
}
sort(user+,user+N+,cmp2);
for(int i=;i<=N;i++){
if(user[i].isShow==)
continue;
printf("%d %05d %d",user[i].ranks,user[i].id,user[i].score);
for(int j=;j<=K;j++){
if(user[i].submitted[j]==){
printf(" -");
}
else{
if(user[i].problem[j]!=-)
printf(" %d",user[i].problem[j]);
else
printf("");
}
}
printf("\n");
}
return ;
}

PAT甲题题解-1075. PAT Judge (25)-排序的更多相关文章

  1. PAT甲题题解-1129. Recommendation System (25)-排序

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789819.html特别不喜欢那些随便转载别人的原创文章又不给 ...

  2. PAT甲题题解-1051. Pop Sequence (25)-堆栈

    将1~n压入最多为m元素的栈 给出k个出栈序列,问你是否能够实现. 能输出YES 否则NO 模拟一遍即可,水题. #include <iostream> #include <cstd ...

  3. PAT甲题题解-1059. Prime Factors (25)-素数筛选法

    用素数筛选法即可. 范围long int,其实大小范围和int一样,一开始以为是指long long,想这就麻烦了该怎么弄. 而现在其实就是int的范围,那难度档次就不一样了,瞬间变成水题一枚,因为i ...

  4. PAT甲题题解-1101. Quick Sort (25)-大水题

    快速排序有一个特点,就是在排序过程中,我们会从序列找一个pivot,它前面的都小于它,它后面的都大于它.题目给你n个数的序列,让你找出适合这个序列的pivot有多少个并且输出来. 大水题,正循环和倒着 ...

  5. PAT甲题题解-1117. Eddington Number(25)-(大么个大水题~)

    如题,大水题...贴个代码完事,就这么任性~~ #include <iostream> #include <cstdio> #include <algorithm> ...

  6. PAT甲题题解-1130. Infix Expression (25)-中序遍历

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789828.html特别不喜欢那些随便转载别人的原创文章又不给 ...

  7. PAT甲题题解-1016. Phone Bills (25)-模拟、排序

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789229.html特别不喜欢那些随便转载别人的原创文章又不给 ...

  8. PAT甲题题解-1021. Deepest Root (25)-dfs+并查集

    dfs求最大层数并查集求连通个数 #include <iostream> #include <cstdio> #include <algorithm> #inclu ...

  9. PAT甲题题解-1024. Palindromic Number (25)-大数运算

    大数据加法给一个数num和最大迭代数k每次num=num+num的倒序,判断此时的num是否是回文数字,是则输出此时的数字和迭代次数如果k次结束还没找到回文数字,输出此时的数字和k 如果num一开始是 ...

随机推荐

  1. C语言实现输出杨辉三角

    1.倒推法实现输出杨辉三角右半部分,代码如下: #include<stdio.h> int main() { ]; printf("请输入行数n:"); scanf(& ...

  2. [python] 在 python2和3中关于类继承的 super方法简要说明

    下面举一个例子,同样的代码使用 python2 和 python3 写的,大家注意两段程序中红色加粗的部分: python2的类继承使用super方法: #-*- coding:utf-8 -*- ' ...

  3. python第三十九课——面向对象(二)之设计类

    1.设计类class 车: #属性 颜色 = red 品牌 = "BMW" 车牌 = "沪A88888" #函数 行驶(): 停止(): 2.实例化车对象 ca ...

  4. BZOJ2580:[USACO]Video Game(AC自动机,DP)

    Description Bessie is playing a video game! In the game, the three letters 'A', 'B', and 'C' are the ...

  5. java中Integer与int装箱拆箱一点收获

    示例代码: class BoxIntInteger { public static void main(String[] args) { Integer a = new Integer(10111); ...

  6. rest_framework源码分析

    CBV&APIView '''原生django as_view方法''' class View(object): http_method_names = ['get', 'post', 'pu ...

  7. 恶意代码技术第一二部分——P201421410029

    学   号:201421410029   中国人民公安大学 Chinese people’ public security university 网络对抗技术 实验报告   实验四 恶意代码技术   ...

  8. linux ssh 应用

    linux 服务器 连接另一个linux服务器 ssh 用户名@IP地址 linux 服务器传输文件到另一个linux服务器 scp 文件名(可多个)  用户名@IP地址:传到的目录 /home

  9. python利用smtplib和MIMETYPE发送邮件

    # -*- coding:utf- -*- import smtplib from email.mime.text import MIMEText sender = '你的发送邮件' my_pass= ...

  10. JS模拟滚动条(有demo和源码下载,支持拖动 滚轮 点击事件)

    由于游览器自带的滚动条在美观方面并不是很好看,所以很多设计师希望通过自己设计出来的滚动条来做这样的效果,JS模拟滚动条其实很早看到jQuery有这样的插件或者KISSY有这样的组件,一直想着自己什么时 ...