其中在排名输出上参照了

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)的更多相关文章

  1. A1075 PAT Judge (25)(25 分)

    A1075 PAT Judge (25)(25 分) The ranklist of PAT is generated from the status list, which shows the sc ...

  2. 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 ...

  3. PAT 甲级 1075 PAT Judge (25分)(较简单,注意细节)

    1075 PAT Judge (25分)   The ranklist of PAT is generated from the status list, which shows the scores ...

  4. PATA1075 PAT Judge (25 分)

    The ranklist of PAT is generated from the status list, which shows the scores of the submissions. Th ...

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

    The ranklist of PAT is generated from the status list, which shows the scores of the submissions. Th ...

  6. A1075 PAT Judge (25 分)

    The ranklist of PAT is generated from the status list, which shows the scores of the submissions. Th ...

  7. PAT 1075. PAT Judge (25)

    题目地址:http://pat.zju.edu.cn/contests/pat-a-practise/1075 此题主要考察细节的处理,和对于题目要求的正确理解,另外就是相同的总分相同的排名的处理一定 ...

  8. 1075 PAT Judge (25)

    排序题 #include <stdio.h> #include <string.h> #include <iostream> #include <algori ...

  9. PAT1075. PAT Judge

    //终于A了,不难却觉着坑多的的题,注意-1的处理,感觉我是受memset置0的束缚了,可以把初试成绩置-1.就不用debug怎么久,注意对于-1的处理,不然漏洞百出 #include<cstd ...

随机推荐

  1. registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped.

    最近在用maven整合SSH做个人主页时候,在eclipse里面使用tomcat7插件发布项目是没有问题的,但当打包成war之后,使用tomcat7单独发布项目,就出现了以下的错误. 严重: Cont ...

  2. windows系统的对象管理

    windows中的对象和高级编程语言中所说的对象还欧区别,准确来讲,windows中的对象其实指的是一种数据结构并且是一种带着“对象头(object head)” 的数据结构!  所以windows中 ...

  3. 【我的Android进阶之旅】Android目录过长造成错误:Failed to crunch file abc_textfield_search_activated_mtrl_alpha.9.png

    一.编译异常描述 一大早来开发一个新的需求,拉取了一个新的分支,然后导入Android Studio之后,编译就报错了,报错如下所示: 错误具体日志如下所示: Information:Gradle t ...

  4. yum install mysql on centos 6.5 zz

    http://www.cnblogs.com/xiaoluo501395377/archive/2013/04/07/3003278.html 1.使用yum命令进行mysql的安装 yum list ...

  5. 浅析Spring AOP

    在正常的业务流程中,往往存在着一些业务逻辑,例如安全审计.日志管理,它们存在于每一个业务中,然而却和实际的业务逻辑没有太强的关联关系. 图1 这些逻辑我们称为横切逻辑.如果把横切的逻辑代码写在业务代码 ...

  6. Appium-Java滑动操作

    Java滑动操作,通常可以直接使用API中AndroidDriver类中的swipe方法,直接进行调用 swipe(int startx, int starty, int endx, int endy ...

  7. MySQL高可用架构之MHA(转)

    简介: MHA(Master High Availability)目前在MySQL高可用方面是一个相对成熟的解决方案,它由日本DeNA公司youshimaton(现就职于Facebook公司)开发,是 ...

  8. python全栈开发从入门到放弃之常用模块和正则

    什么是模块? 常见的场景:一个模块就是一个包含了python定义和声明的文件,文件名就是模块名字加上.py的后缀. 但其实import加载的模块分为四个通用类别: 1 使用python编写的代码(.p ...

  9. 高并发下hystrix熔断超时及concurrent.RejectedExecutionException: Rejected command because thread-pool queueSize is at rejection threshold问题

    我的一个项目并发200+,观察服务器的日志发现出现了大量的熔断超时偶尔会闪现出RejectedExecutionException: Rejected command because thread-p ...

  10. 基于TSUNG对MQTT进行压力测试-基础概念温习

    [单台Broker压测结果]请移步另一篇博客:http://www.cnblogs.com/lingyejun/p/7941271.html 一.TCP报头部中的SYN.FIN.ACK: ACK : ...