当前位置:网站首页>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;
}
边栏推荐
- Is this code PHP MySQL redundant?
- Flutter环境配置保姆级教程,让doctor一绿到底
- 07 data import sqoop
- How to get the password of cpolar?
- Solution of mysql8 forgetting password file in Windows Environment
- 简洁、快速、节约内存的Excel处理工具EasyExcel
- What is the significance of the college entrance examination
- flume 190 INSTALL
- Beautiful and intelligent, Haval H6 supreme+ makes Yuanxiao travel safer
- JS reduce accumulator
猜你喜欢

js数组常用方法

UVM learning - object attribute of UVM phase

1287_FreeRTOS中prvTaskIsTaskSuspended()接口实现分析

MongoDB-快速上手MongoDB命令行的一些简单操作

拆解美图SaaS:开着飞机换引擎

sqoop创建job出现的一系列问题解决方法

Easyexcel, a concise, fast and memory saving excel processing tool

Mongodb quickly get started with some simple operations of mongodb command line

Allure -- common configuration items

Database dictionary Navicat automatic generation version
随机推荐
Network communication learning
Sum the two numbers to find the target value
Sus system availability scale
Determine whether there are duplicate elements in the array
UVM——Callback
《实习报告》Skywalking分布式链路追踪?
[jetbrain rider] an exception occurred in the construction project: the imported project "d:\visualstudio2017\ide\msbuild\15.0\bin\roslyn\microsoft.csh" was not found
sqoop的表的导入
Mongodb quickly get started with some simple operations of mongodb command line
使用Windbg静态分析dump文件(实战经验总结)
1287_ Implementation analysis of prvtaskistasksuspended() interface in FreeRTOS
2. Hacking lab script off [detailed writeup]
The nanny level tutorial of flutter environment configuration makes the doctor green to the end
Win11 arm系统配置.net core环境变量
Merge ordered sequence
"Talking about podcasts" vol.352 the age of children: breaking the inner scroll, what can we do before high school?
对话吴纲:我为什么笃信“大国品牌”的崛起?
shell编程01_Shell基础
02-taildir source
两数之和,求目标值