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;
}
PAT1075. PAT Judge (25)的更多相关文章
- A1075 PAT Judge (25)(25 分)
A1075 PAT Judge (25)(25 分) The ranklist of PAT is generated from the status list, which shows the sc ...
- 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 PA ...
- PAT 甲级 1075 PAT Judge (25分)(较简单,注意细节)
1075 PAT Judge (25分) The ranklist of PAT is generated from the status list, which shows the scores ...
- PATA1075 PAT Judge (25 分)
The ranklist of PAT is generated from the status list, which shows the scores of the submissions. Th ...
- 10-排序5 PAT Judge (25 分)
The ranklist of PAT is generated from the status list, which shows the scores of the submissions. Th ...
- A1075 PAT Judge (25 分)
The ranklist of PAT is generated from the status list, which shows the scores of the submissions. Th ...
- PAT 1075. PAT Judge (25)
题目地址:http://pat.zju.edu.cn/contests/pat-a-practise/1075 此题主要考察细节的处理,和对于题目要求的正确理解,另外就是相同的总分相同的排名的处理一定 ...
- 1075 PAT Judge (25)
排序题 #include <stdio.h> #include <string.h> #include <iostream> #include <algori ...
- PAT1075. PAT Judge
//终于A了,不难却觉着坑多的的题,注意-1的处理,感觉我是受memset置0的束缚了,可以把初试成绩置-1.就不用debug怎么久,注意对于-1的处理,不然漏洞百出 #include<cstd ...
随机推荐
- python3在centos6.6上的安装
建议:在看这个文档操作前,最好先参考一下这个:https://www.cnblogs.com/bookwed/p/10251236.html,是解决pip安装模块时,提示ssl版本低的问题. #提前的 ...
- 并发编程 - 进程 - 1.开启子进程的两种方式/2.查看pid/3.Process对象的其他属性或方法/4.守护进程
1.开启子进程的两种方式: # 方式1: from multiprocessing import Process import time def task(name): print('%s is ru ...
- 关于Android项目隐藏标题栏的方法总结
1.在代码中添加这么一行代码 this.requestWindowFeature(Window.FEATURE_NO_TITLE); 注意:这段代码需要写在setContentView()之前,否则会 ...
- Python的subprocess模块(一)
原文连接:http://www.cnblogs.com/wang-yc/p/5624880.html 一.简介 subprocess最早在2.4版本引入.用来生成子进程,并可以通过管道连接他们的输入/ ...
- python中读取json文件报错,TypeError:the Json object must be str, bytes or bytearray,not ‘TextIOWrapper’
利用python中的json读取json文件时,因为错误使用了相应的方法导致报错:TypeError:the Json object must be str, bytes or bytearray,n ...
- Redis for Python开发手册
redis基本命令 String Set set(name, value, ex=None, px=None, nx=False, xx=False) 在Redis中设置值,默认,不存在则创建,存在则 ...
- UVA10026:Shoemaker's Problem(贪心)
题目链接: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=68990#problem/K 题目需求:鞋匠有n个任务,第i个任务要花费ti ...
- 压力测试工具sysbench
sysbench是一个模块化.跨平台.多线程基准测试工具,主要用于测试不同系统参数下的数据库负载情况,本文主要介绍0.4版本的使用.sysbench主要用于以下性能测试: 文件I/O性能 调度 内存分 ...
- 把当前文件夹的xlsx或xls文件合并到一个excel文件中的不同sheet中
把当前文件夹的xlsx或xls文件合并到一个excel文件中的不同sheet中步骤如下: 把需要合并的文件放到同一个文件夹 在该文件夹中新建一个excel文件 打开新建的excel问价,把鼠标放到sh ...
- beego——session模块
session介绍 session是一个独立的模块,即你可以那这个模块应用于其它Go程序中. session模块是用来存储客户端用户,session目前只支持cookie方式的请求,如果客户端不支持c ...