有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. 根据权限显示accordion

    前端界面: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Home.asp ...

  2. 14.浏览器屏幕缩放bug修复

    问题:浏览器缩放时,轮播图显示不全,滚动水平滚动条,发现图片缺失 解决:隐藏水平滚动条,页面都只提供垂直滚动条的需求 global.css /* 水平超出部分默认隐藏 */ #app { overfl ...

  3. mybatis源码探索笔记-2(构建SqlSession并获取代理mapper)

    前言 上篇笔记我们成功的装载了Configuration,并写入了我们全部需要的信息.根据这个Configuration创建了DefaultSqlSessionFactory.本篇我们实现构建SqlS ...

  4. VUE父子组件相互传值

    passer.vue中代码 首先在文件中引入组件 import canvasDraw from '@/components/CanvasDraw/canvasDraw' 局部注册组件:componen ...

  5. vue 和 jquery混合使用

    有时候只要想到要用的 vue.js 的时候就会惯性的想起用vue-cli手脚架搭建一个项目,但是有时候的业务场景并不适合用vue-cli手脚架,这个时候使用vue+jquery混合使用,把他们的优点结 ...

  6. 2019年ipa发布苹果应用商店审核指南

    https://baijiahao.baidu.com/s?id=1623886553597961077&wfr=spider&for=pc ipa 发布审核指南 说明: 本指南为初版 ...

  7. MyBatis+Oracle实现主键自增长的几种常用方式

    一.使用selectKey标签 <insert id="addLoginLog" parameterType="map" > <selectK ...

  8. Python 使用pillow 操作图像

    文档:https://pillow.readthedocs.io/en/stable/index.html 计算机图像基础 颜色和RGBA值 计算机程序通常将图像中的颜色表示为 RGBA 值.RGBA ...

  9. 使用SQL语句还原数据库 2012.3.20

    --返回由备份集内包含的数据库和日志文件列表组成的结果集. --主要获得逻辑文件名 USE master RESTORE FILELISTONLY FROM DISK = 'g:\back.Bak' ...

  10. Topcoder SRM 590 Fox And City

    Link 注意到原图给的是一个无向连通图. 如果在原图中两点之间有一条无向边,那么这两点到\(1\)的距离之差不大于\(1\). 这个命题的正确性是显然的,我们考虑它的逆命题: 给定每个点到\(1\) ...