有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
*/

  

最新文章

  1. iOS 引入framework的常见问题和原理
  2. ADF_Database Develop系列2_设计数据库表之Table Partitions/Create Users/Generate DDL
  3. C++中的预处理
  4. memcached(二)事件模型源码分析
  5. Spark Streaming实时计算框架介绍
  6. selenium和Firefox版本不兼容
  7. PHP中::、-&gt;、self、$this操作符的区别
  8. iOS开发——笔记篇&amp;关于字典plist读取/字典转模型/自定义View/MVC/Xib的使用/MJExtension使用总结
  9. UpdatePanel的用法
  10. sql查阅每一月的数据
  11. [原创作品] Express 4.x 接收表单数据
  12. Class ThreadPoolExecutor
  13. win10+vs2010+cuda7.5安装及配置
  14. fs模块练习
  15. netty源码理解(二) serverstrap.bind()
  16. MySQL高级函数case的使用技巧----与sum结合实现分段统计
  17. The Interview Outline
  18. 【vue】[Vue warn]: $attrs is readonly. 只读
  19. npm国内镜像介绍
  20. Neutron命令测试1

热门文章

  1. RADIUS Authentication with WPA2-Enterprise
  2. Cisco AP-如何调整LAP信道
  3. 学习笔记(7)- 基于LSTM的对话模型
  4. 添加COOKIE
  5. floyd的魔改应用——洛谷P2419 [USACO08JAN]牛大赛Cow Contest 题解
  6. 3.java发展简史
  7. CSS - 表格细线边框
  8. AttributeError: &#39;Word2Vec&#39; object has no attribute &#39;vocab&#39;
  9. color转成image对象
  10. 复盘实战营一期毕业典礼----HHR计划----以太入门课--第一课