有n个考场,每个考场都有若干数量个考生,现给出各个考场中考生的准考证号和分数,要求将所有考生的分数从高到低排序,并输出

#include<iostream>
#include<string.h>
#include<algorithm>
//#include<map> using namespace std;
struct Student
{
char id[15]; //准考证号
int score; //分数
int location_number; //考场号
int location_rank; //考场内排名
} stu[30010]; bool cmp(Student a,Student b)
{
if(a.score != b.score) return a.score> b.score; //按分数从高到底排序
else return strcmp(a.id,b.id)<0; //分数按照准考证号从小到大排序
} int main()
{
int n,k,num=0;
cin>>n;//n为考场数
for(int i=0;i<n;i++)
{
cin>>k;
for(int j=0;j<k;j++)
{
cin>>stu[num].id>>stu[num].score;
stu[num].location_number=i;
num++;
}
sort(stu + num-k,stu+num,cmp);
stu[num-k].location_rank=1; //对于考场的第一名rank记为1
for(int j = num-k+1;j<num;j++)
{
if(stu[j].score==stu[j-1].score)
{
stu[j].location_rank=stu[j-1].location_rank;
}
else
{
stu[j].location_rank=j+1-(num-k);
}
}
}
cout<<num<<endl;
sort(stu,stu+num,cmp);
int r=1;
for (int i=0;i<num;i++)
{
if(i>0&&stu[i].score != stu[i-1].score)
{
r=i+1;
}
cout<<stu[i].id;
cout<<r<<stu[i].location_number<<stu[i].location_rank<<endl;
}
return 0;
}
/*
输入样例:
2
5
1234567890001 95
1234567890005 100
1234567890003 95
1234567890002 77
1234567890004 85
4
1234567890013 65
1234567890011 25
1234567890014 100
1234567890012 85
*/

  

PAT A1025 pat ranking的更多相关文章

  1. PAT A1025 PAT Ranking(25)

    题目描述 Programming Ability Test (PAT) is organized by the College of Computer Science and Technology o ...

  2. A1025 PAT Ranking (25)(25 分)

    A1025 PAT Ranking (25)(25 分) Programming Ability Test (PAT) is organized by the College of Computer ...

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

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

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

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

  5. PAT 1141 PAT Ranking of Institutions

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

  6. A1025. PAT Ranking

    Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhe ...

  7. PAT甲级——A1025 PAT Ranking

    Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhe ...

  8. 【算法学习记录-排序题】【PAT A1025】PAT Ranking

    Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhe ...

  9. PAT甲级真题 A1025 PAT Ranking

    题目概述:Programming Ability Test (PAT) is organized by the College of Computer Science and Technology o ...

随机推荐

  1. 无法打开物理文件 XXX.mdf",操作系统错误 5.5(拒绝访问) 的解决办法

    用T-SQL命令附加数据库时,出现如下异常信息: 无法打开物理文件 XXX.mdf".操作系统错误 5:"5(拒绝访问.)". (Microsoft SQL Server ...

  2. websocket 无法查看Data

    websocket 是浏览器新的信息传输协议,记录一些遇到的问题: 调试相关: websocket 连接以后可以在Chrome tools 中的network下看到,如图 要查看通信内容可以选中点击f ...

  3. leetcode菜鸡斗智斗勇系列(8)--- Find N Unique Integers Sum up to Zero

    1.原题: https://leetcode.com/problems/find-n-unique-integers-sum-up-to-zero/ Given an integer n, retur ...

  4. python调用scala或java包

    项目中用到python操作hdfs的问题,一般都是使用python的hdfs包,然而这个包初始化起来太麻烦,需要: from pyspark impport SparkConf, SparkConte ...

  5. Bugku-CTF加密篇之ok(Ook!)

  6. C++判断txt文件编码格式

    转载:https://blog.csdn.net/kikityan/article/details/89923808 记事本打开txt文件,然后另存,有四种编码格式可供选择,分别是:ANSI     ...

  7. Fedora26同步仓库缓存失败问题实记

    虽然目前的linux已经能自动选择最快的源,但是官方提供的镜像列表仍然较少,速度虽有所提升但是整体依然较慢,阿里的源作为国内最快的源却没有被纳入官方提供的源中 国内常使用的源有阿里,中科大,清华,网易 ...

  8. locust --hellp

    1. Locust简介 Locust是使用Python语言编写实现的开源性能测试工具,简洁.轻量.高效,并发机制基于gevent协程,可以实现单机模拟生成较高的并发压力. 官网:https://loc ...

  9. sshpass安装以及使用

    centos7如何安装sshpass 先安装epel yum install -y epel-release yum repolist 安装完成epel之后,就可以按照sshpass了 yum ins ...

  10. Centos7618安装Docker

    本文基于Centos7.6.18进行安装与测试 移除旧的版本: $ sudo yum remove docker \ docker-client \ docker-client-latest \ do ...