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 ...
随机推荐
- 多线程入门-第五章-线程的调度与控制之yield
yield与sleep类似,只是不能指定暂停多长时间,并且只能让同优先级的线程有执行的机会,让位时间不固定. /* yield使用 */ public class ThreadTest04 { pub ...
- LeetCode_Search in Rotated Sorted Array
题目: Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 ...
- mac配置python自然语言处理环境
一.nltk安装 Ⅰ.工具安装步骤 1.根据python版本从 https://pypi.python.org/pypi/setuptools 下载对应版本的setuptools.然后,在终端下运行, ...
- qemu进程页表和EPT的同步问题
背景分析: 在之前分析EPT violation的时候,没有太注意qemu进程页表和EPT的关系,从虚拟机运行过程分析,虚拟机访存使用自身页表和EPT完成地址转换,没有用到qemu进程页表,所以也就想 ...
- linux 这是定时任务
1. 编写shell脚本:vim test.sh #/bin/bash echo "hello world" 2.crontab任务配置基本格式: * * * * * comm ...
- python web框架 django 练习1 django 1.11版本
django练习 在我自己项目里创建一个xiaoliu的文件夹 里面创建s1.py 文件 s1.py文件 里面写各种函数 from django.shortcuts import HttpRespon ...
- ajax示例
ajax(Asynchronous Javascript And XML)翻译成中文就是异步的javascript和XML,即用javascript语言与服务器进行异步交互,传输的数据为XML(当然, ...
- Java基础知识陷阱(二)
本文发表于本人博客. 上次说了一些关于字符串的知识,都是比较基础的,那这次也说下关于对象地址问题,比如传参.先看下面代码: public void changeInt(int a){ a = ; } ...
- php中获得数组长度的方法
php中获得数组长度的方法 count统计数组里元素的个数: strlen是统计数组中元素的长度: 你如果想统计数组中所有元素的长度,那就用循环统计吧tqeb 代码: $a = array( ...
- [随记][asp.net基础]Page_Load和OnLoad
标题:[随记][asp.net基础]Page_Load和OnLoad 一.前言 东西好久不用.不想,就会忘,所以没办法,只好记下来. 二.正文 aspx页面加载的时候会自动执行Page_Load,也会 ...