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 ...
随机推荐
- Java技术大牛需要学习的25个技能
你需要精通面向对象分析与设计(OOA/OOD).涉及模式(GOF,J2EEDP)以及综合模式.你应该了解UML,尤其是class.object.interaction以及statediagrams. ...
- 前端开发 - JQuery - 下
二十五.jquery的事件 <!DOCTYPE html> <html lang="en"> <head> <meta charset=& ...
- 用Python爬虫爬取广州大学教务系统的成绩(内网访问)
用Python爬虫爬取广州大学教务系统的成绩(内网访问) 在进行爬取前,首先要了解: 1.什么是CSS选择器? 每一条css样式定义由两部分组成,形式如下: [code] 选择器{样式} [/code ...
- 剑指Offer——字符流中第一个不重复的字符
题目描述: 请实现一个函数用来找出字符流中第一个只出现一次的字符.例如,当从字符流中只读出前两个字符"go"时,第一个只出现一次的字符是"g".当从该字符流中读 ...
- Preparing Olympiad---cf550B(DFS或者状态压缩模板)
比赛链接:http://codeforces.com/problemset/problem/550/B 给你n个数,选出来只是2个然后求他们的和在L和R的区间内,并且选出来的数中最大值和最小值的差不得 ...
- SVN导出Maven项目
1.从SVN检出项目 -> 作为工作空间中的项目检出 2.转换成Maven project 3.将Maven Project 转化成 Maven app 右击项目-> Properties ...
- Linux chmod命令
chmod用于管理文件或目录的权限,文件或目录权限的控制分别以读取(r).写入(w).执行(x)3种 可读可写可执行,抽象的用二进制来表示 1 代表拥有该权限,0 代表没有该权限,这样我们就可以看到 ...
- mysql 数据库查询最后两条数据
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u011925175/article/details/24186917 有一个mysql数据库的 ...
- HDU中大数实现的题目,持续更新(JAVA实现)
HDU1002:大数加法,PE了N次 import java.util.Scanner; import java.math.*; public class Main { public static v ...
- 解析库之——beautifulsoup
阅读目录 一 介绍 二 基本使用 三 遍历文档树 四 搜索文档树 五 修改文档树 六 总结 一 介绍 Beautiful Soup 是一个可以从HTML或XML文件中提取数据的Python库.它能够通 ...