当前位置:网站首页>HDU1236 排名(结构体排序)
HDU1236 排名(结构体排序)
2022-07-02 07:04:00 【Woodenman杜】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1236
Question
今天的上机考试虽然有实时的Ranklist,但上面的排名只是根据完成的题数排序,没有考虑
每题的分值,所以并不是最后的排名。给定录取分数线,请你写程序找出最后通过分数线的
考生,并将他们的成绩按降序打印。
Input
测试输入包含若干场考试的信息。每场考试信息的第1行给出考生人数N ( 0 < N
< 1000 )、考题数M ( 0 < M < = 10 )、分数线(正整数)G;第2行排序给出第1题至第M题的正整数分值;以下N行,每行给出一
名考生的准考证号(长度不超过20的字符串)、该生解决的题目总数m、以及这m道题的题号
(题目号由1到M)。
当读入的考生人数为0时,输入结束,该场考试不予处理。
Output
对每场考试,首先在第1行输出不低于分数线的考生人数n,随后n行按分数从高
到低输出上线考生的考号与分数,其间用1空格分隔。若有多名考生分数相同,则按他们考
号的升序输出。

Solve
题目意思很简单,计算每位考生的得分,把过线的考生找出来,按成绩降序、考生号升序的顺序输出。
我这里定义了一个考生信息的结构体,并重载了 < 运算符,再借用 sort 函数实现结构体排序,有一定的参考价值。
AC Code
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int n, m, g, a[11], num, x;
struct Node{
string user; //考号
int score; //得分
//自定义排序,分数降序,考号升序
bool operator < (const Node &a)const{
if(a.score == score) return user < a.user;
else return score > a.score;
}
}node[1010];
int main(void)
{
while(cin >>n && n != 0){
cin >>m >>g;
//初始化分数
for(int i = 1; i <= n; i++) node[i].score = 0;
//读入题
for(int i = 1; i <= m; i++) cin >>a[i];
//读入答题情况
for(int i = 1; i <= n; i++){
cin >>node[i].user >>num;
//计算分数
while(num--){
cin >>x;
node[i].score += a[x];
}
}
//排序
sort(node+1, node+1+n);
//输出结果
int cnt = 0;
for(int i = 1; i <= n; i++){ //计算过线人数
if(node[i].score >= g) cnt++;
else break;
}
cout <<cnt <<endl;
for(int i = 1; i <= cnt; i++){ //输出数据
cout <<node[i].user <<" " <<node[i].score <<endl;
}
}
return 0;
}
边栏推荐
- Shapiro Wilk normal analysis by SPSS
- Flutter——Canvas自定义曲线图
- In the face of uncertainty, the role of supply chain
- Operator-1初识Operator
- stm32和電機開發(上比特系統)
- [MySQL] an exception occurs when connecting to MySQL: connection must be valid and open
- 面对不确定性,供应链的作用
- Easyexcel, a concise, fast and memory saving excel processing tool
- 02-taildir source
- Mongodb quickly get started with some simple operations of mongodb command line
猜你喜欢

The URL in the RTSP setup header of the axis device cannot take a parameter

Post disaster reconstruction -- Floyd thought

618再次霸榜的秘密何在?耐克最新财报给出答案
![[Fantasy 4] introduction and use of UMG components (under update...)](/img/33/7e3b74192b7fd73d5145f85e061d1f.png)
[Fantasy 4] introduction and use of UMG components (under update...)
![[unity3d] nested use layout group to make scroll view with dynamic sub object height](/img/b2/edab4ab48e1401934dcce7218df662.png)
[unity3d] nested use layout group to make scroll view with dynamic sub object height

Win11 arm系统配置.net core环境变量

Determine whether there are duplicate elements in the array

Allure -- common configuration items

Leetcode+ 76 - 80 storm search topic
![[TS] 1368 seconds understand typescript generic tool types!](/img/2b/58a850b52ce8a9b2e6e7b6b72b0fe5.jpg)
[TS] 1368 seconds understand typescript generic tool types!
随机推荐
What is the significance of the college entrance examination
PCL之滤波
Mysql database remote access permission settings
面对不确定性,供应链的作用
网络通信学习
2. Hacking lab script off [detailed writeup]
使用sqlcipher打开加密的sqlite方法
2.hacking-lab脚本关[详细writeup]
传输优化抽象
axis设备的rtsp setup头中的url不能带参
Importing tables from sqoop
2021-10-02
合并有序数列
14.信号量的代码实现
What are the popular frameworks for swoole in 2022?
Considerations for Apache deploying static web page projects
(五)APA场景搭建之挡位控制设置
Read H264 parameters from mediarecord recording
【TS】1368- 秒懂 TypeScript 泛型工具类型!
session-cookie与token