PAT A1025 pat ranking
有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的更多相关文章
- PAT A1025 PAT Ranking(25)
题目描述 Programming Ability Test (PAT) is organized by the College of Computer Science and Technology o ...
- A1025 PAT Ranking (25)(25 分)
A1025 PAT Ranking (25)(25 分) Programming Ability Test (PAT) is organized by the College of Computer ...
- PAT A1141 PAT Ranking of Institutions (25 分)——排序,结构体初始化
After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...
- [PAT] 1141 PAT Ranking of Institutions(25 分)
After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...
- PAT 1141 PAT Ranking of Institutions
After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...
- A1025. PAT Ranking
Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhe ...
- PAT甲级——A1025 PAT Ranking
Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhe ...
- 【算法学习记录-排序题】【PAT A1025】PAT Ranking
Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhe ...
- PAT甲级真题 A1025 PAT Ranking
题目概述:Programming Ability Test (PAT) is organized by the College of Computer Science and Technology o ...
随机推荐
- redhat 7.6安装kvm
安装 yum install qemu-kvm libvirt virt-install virt-manager openssh-askpass yum install qemu-kvm-tools ...
- 正确的上网姿势:ubuntu18.04使用clash
本文为本人将CFW(Clash For Windows)上的配置文件应用到ubuntu上面的操作备忘,仅供个人使用 首先下载已经打包的clash压缩包:https://github.com/Dream ...
- .NET Core快速入门教程 4、使用VS Code进行C#代码调试的技巧
一.前言 什么是代码调试? 通过调试可以让我们了解代码运行过程中的代码执行信息,比如变量的值等等.通常调试代码是为了方便我们发现代码中的bug. 本篇开发环境 1.操作系统: Windows 10 X ...
- POJ2516 Minimum Cost
亲爱的,一个货物销售者,现在遇到了一个大问题,他需要你的帮助.在他的销售区域有 N 个店主(从 1 到 N)向他储存货物,Dearboy 有M 个供应点(从 1 到 M),每个供应点提供 K 种不同的 ...
- ZOJ4110 Strings in the Pocket(2019浙江省赛)
给出两个字符串,询问有多少种反转方法可以使字符串1变成字符串2. 如果两个串相同,就用马拉车算法找回文串的数量~ 如果两个串不同,从前往后找第一个不同的位置l,从后往前找第二个不同的位置r,反转l和r ...
- Servlet的基本使用
1.pom.xml导入包 <dependency> <groupId>javax.servlet</groupId> <artifactId>javax ...
- cemtos安装python
mkdir python3cd python3/yum -y install gcc*yum install zlib-devel bzip2-devel openssl-devel ncurses- ...
- oracle用户密码忘记怎么修改
安装完数据库很久不用常常会忘记其密码,碰到这种情况不要动不动就重装数据库,按其下方法修改即可. 一:忘记sys,system用户的密码 1,在开始菜单点击‘运行’,输入‘cmd’,打开命令提示窗口,输 ...
- 前端学习 之 CSS(三)
九:浮动 浮动是css里面布局最多的一个属性,也是很重要的一个属性. float:表示浮动的意思. 属性值: none: 表示不浮动,默认 left: 表示左浮动 right:表示右浮动 例: htm ...
- 2.9 logistic回归中的梯度下降法(非常重要,一定要重点理解)
怎么样计算偏导数来实现logistic回归的梯度下降法 它的核心关键点是其中的几个重要公式用来实现logistic回归的梯度下降法 接下来开始学习logistic回归的梯度下降法 logistic回归 ...