其中在排名输出上参照了

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. Java中“==和equals”的区别

    (1)“==” 是判断地址的: (2)至于equals,String类型重写了 equals()方法,判断内容是否相等,因此 equals 是相等的:

  2. php判断密码强度函数

    其实就是一些策略正则,写好了就留下来以后用. print_r(getPasswordStrength('s1212adsddfASD;\'g;\'gh.h,h..;')); function getP ...

  3. centos下apache安装

    ./configure --prefix=/usr/local/apache2 --enable-so --enable-proxy --enable-proxy-connect --enable-p ...

  4. Mybatis框架学习总结-解决字段名与实体类属性名不相同的冲突

    在平时的开发中,我们表中的字段名和表对应实体类的属性名称不一定是完全相同的. 1.准备演示需要使用的表和数据 CREATE TABLE orders( order_id INT PRIMARY KEY ...

  5. (2.4)Mysql之SQL基础——下载与使用测试库

    (2.4)SQL基础——下载与使用测试库 1.查看与下载测试数据库 2.查看安装向导视图 3.安装 [1]安装:解压后用 mysql 命令安装(记得加上set autocommit=1) [2]核验: ...

  6. php about session store db or cache

    PHP关于Session的配置: 在php.ini中配置为:session.name = PHPSESSID 在请求开始的时候,会话名称会被重置并存储到session.name配置项. 所以要想在不改 ...

  7. 取MAC地址 (含多网卡),最好的方法,支持Vista,Win7

    取MAC地址 (含多网卡),最好的方法,支持Vista,Win7 unit Unit1; interface usesWindows, Messages, SysUtils, Variants, Cl ...

  8. SQL Server去重和判断是否为数字——OBJECT_ID的使用

    sql 语句查询时去掉重复项: 使用 distinct 去掉重复项: 首先可以明确的看到存在重复的名字,那么接下来就让我们试试使用 distinct 去重吧. select distinct * fr ...

  9. hdu6121 Build a tree

    地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6121 题面: Build a tree Time Limit: 2000/1000 MS (J ...

  10. 【转载】IDEA:放置型塔防备忘录

    下周开始做原型了,我需要再次细细的整理一遍设计思路,确保每一个设计都能为了我所追求的玩家体验添砖加瓦,而不是互相打架.同时本文还能提供最原始的VISION,待到将来开发万一陷入泥淖,翻出此文来可以起到 ...