题目地址:http://pat.zju.edu.cn/contests/pat-a-practise/1075

此题主要考察细节的处理,和对于题目要求的正确理解,另外就是相同的总分相同的排名的处理一定要熟练,还有就是编译没有通过为零分,没有提交显示为"-":

#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std; const int NUM=;
vector<int> p();
int N,K,M;
struct User
{
User()
{
scores.resize();
for(int i=;i<=;++i)
{
scores[i]=-;
}
totalScores=;
id=NUM;
}
int id;
int totalScores;
vector<int> scores;
bool operator<(const User& rhs) const
{ if(totalScores!=rhs.totalScores)
{
return totalScores>rhs.totalScores;
}
int psl=,psr=;
for(int i=;i<=K;++i)
{
if(p[i]==scores[i])
++psl;
if(p[i]==rhs.scores[i])
++psr;
}
if(psl!=psr)
{
return psl>psr;
}
else
{
return id<rhs.id;
}
}
}; vector<User> users(NUM);
int _tmain(int argc, _TCHAR* argv[])
{
freopen("1075.txt","r",stdin);
scanf("%d %d %d",&N,&K,&M);
int i;
for(i=;i<=K;++i)
{
scanf("%d",&p[i]);
}
int userID,pID,partialScore;
int totalUsers=;
for(i=;i<M;++i)
{
scanf("%d %d %d",&userID,&pID,&partialScore);
if(partialScore==-)
{
if(users[userID].scores[pID]<)
users[userID].scores[pID]=;
continue;
}
else if(partialScore>users[userID].scores[pID])
{
if(users[userID].scores[pID]>=)
users[userID].totalScores+=partialScore-users[userID].scores[pID];
else
users[userID].totalScores+=partialScore;
users[userID].scores[pID]=partialScore;
}
if(users[userID].id==NUM)
{
users[userID].id=userID;
++totalUsers;
}
}
sort(users.begin()+,users.begin()+N+);
int curRank=;
int curTotalScore=users[].totalScores;
int j,sameRank=-;
for(i=;i<=totalUsers;++i)
{
if(curTotalScore>users[i].totalScores)
{
++curRank;
curRank+=sameRank;
sameRank=;
curTotalScore=users[i].totalScores;
}
else
++sameRank;
printf("%d %.5d %d",curRank,users[i].id,users[i].totalScores);
for(j=;j<=K;++j)
{
if(users[i].scores[j]>=)
printf(" %d",users[i].scores[j]);
else
printf(" -");
}
printf("\n");
}
return ;
}

PAT 1075. PAT Judge (25)的更多相关文章

  1. PAT 1075 PAT Judge[比较]

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

  2. PAT 1075. PAT Judge

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

  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. A1075 PAT Judge (25)(25 分)

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

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

  6. PAT 1085 PAT单位排行(25)(映射、集合训练)

    1085 PAT单位排行(25 分) 每次 PAT 考试结束后,考试中心都会发布一个考生单位排行榜.本题就请你实现这个功能. 输入格式: 输入第一行给出一个正整数 N(≤10​5​​),即考生人数.随 ...

  7. PTA PAT排名汇总(25 分)

    PAT排名汇总(25 分) 计算机程序设计能力考试(Programming Ability Test,简称PAT)旨在通过统一组织的在线考试及自动评测方法客观地评判考生的算法设计与程序设计实现能力,科 ...

  8. PAT A1141 PAT Ranking of Institutions (25 分)——排序,结构体初始化

    After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...

  9. [PAT] 1141 PAT Ranking of Institutions(25 分)

    After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...

随机推荐

  1. Codeforces Round #327 div2

    Problem_A(591A): 题意: 有一段长度为l的路,两个人分别在两个端点,1, l. 现在已知每个人的速度为p,q. 求第一个人(初始位置在1)在他们第二次相遇的时候的位置. 当他们相遇的时 ...

  2. location.hash 详解

    前年9月twitter改版. 一个显著变化,就是URL加入了"#!"符号.比如,改版前的用户主页网址为 http://twitter.com/username 改版后,就变成了 h ...

  3. Echarts-JAVA

    http://www.oschina.net/p/echarts-java http://my.oschina.net/flags/blog/316920

  4. MySQL JDBC的setFetchSize

    MySQL JDBC的setFetchSize http://uuhorse.iteye.com/blog/2163582 http://blog.sina.com.cn/s/blog_6706203 ...

  5. HDU 2844 Coins(多重背包)

    点我看题目 题意 :Whuacmers有n种硬币,分别是面值为A1,A2,.....,An,每一种面值的硬币的数量分别是C1,C2,......,Cn,Whuacmers想买钱包,但是想给人家刚好的钱 ...

  6. POJ 3264 Balanced Lineup(RMQ)

    点我看题目 题意 :N头奶牛,Q次询问,然后给你每一头奶牛的身高,每一次询问都给你两个数,x y,代表着从x位置上的奶牛到y位置上的奶牛身高最高的和最矮的相差多少. 思路 : 刚好符合RMQ的那个求区 ...

  7. 【POJ】1692 Crossed Matchings

    经典DP,想了很久,开始想复杂了. #include <iostream> using namespace std; #define MAXNUM 100 int mymax(int a, ...

  8. find和findstr

    find与findstr 例“ 在文件中搜索字符串. 1.findstr . 2.txt 或 Findstr "." 2.txt 从文件2.txt中查找任意字符,不包括空字符或空行 ...

  9. c语言输入与输出库函数#include<stdio.h>

    last modified: 2010-05-28 输入与输出<stdio.h> 头文件<stdio.h>定义了用于输入和输出的函数.类型和宏.最重要的类型是用于声明文件指针的 ...

  10. CLR C++ Set Word CustomDocumentProperties

    // WordIssue.cpp : main project file. #include "stdafx.h" using namespace System; using na ...