有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. 【笔记3-用户模块】从0开始 独立完成企业级Java电商网站开发(服务端)

    数据表结构设计 关系设计 为什么不用外键? 分库分表有外键会非常麻烦,清洗数据也很麻烦.数据库内置触发器也不适合采用. 查业务问题的后悔药--时间戳 create_time 数据创建时间 update ...

  2. acm数论之旅---扩展欧几里得算法

    度娘百科说: 首先, ax+by = gcd(a, b) 这个公式肯定有解 (( •̀∀•́ )她说根据数论中的相关定理可以证明,反正我信了) 所以 ax+by = gcd(a, b) * k 也肯定 ...

  3. WordPress 网站迁移

    最近想把本地的WordPress迁移到我的Linux虚拟机里面,是不是很无聊,哈哈哈,接下来就是一过程了,其实这个和迁移到线上是一样的, 1.首先将本地的文件WordPress通过FTP传到虚拟机上: ...

  4. ZOJ1006 Do the Untwist

    简单模拟~ #include<bits/stdc++.h> using namespace std; ; int a[maxn]; unordered_map<char,int> ...

  5. windows下如何快速删除大文件

    rmdir  磁盘:\文件夹的名字  /s /q; eg:rmdir E:\vue_workspace\KB\day08    /s/q /S 表示除目录本身外,还将删除指定目录下的所有子目录和文件. ...

  6. CSS样式的引入&区别&权重&CSS层叠性&CSS样式的来源

    CSS样式的引入: 内部样式: 内部样式:写在当前页面style标签中的样式 内联样式:写在style属性中的样式 外部样式: link标签引入的CSS文件 @import引入的CSS文件,需要写在c ...

  7. 大盘及策略收益率的公式推导与Python代码

    一.模型前提与假设 设策略总天数为\(n\).第\(t\)日大盘的收盘价为\(P_t\).第\(t\)日的单日收益率为\(r_t\).\(n\)天的累积收益率为\(r_{cum}\) 假设策略仅买卖大 ...

  8. 刚开始用springboot踩的好多坑!!!

    今天,刚开始就在刚才我留下了激动的泪水,因为我捯饬springboot已经有几天了,我通过看视频学的,但是坑实在是太多了,今年是鼠年~~~LOL----瘟疫之源来了, 被困在了老家不能走,老家网实在是 ...

  9. 【SSM】日志框架 logback

    logback.xml <?xml version="1.0" encoding="UTF-8" ?> <configuration scan ...

  10. [理解] C++ 中的 源文件 和 头文件

    我是学 C井 的, 现在在工作中主要使用的编程语言是 Java, 还记得当初在第一次接触到 Cpp 的时候, 听到的第一个概念就是 Cpp 的头文件和源文件, 当初理解了好久, 死活都弄不明白, 现在 ...