当前位置:网站首页>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;
}
边栏推荐
- 使用sqlcipher打开加密的sqlite方法
- VSCode工具使用
- JSP webshell免杀——webshell免杀
- [unity3d] cannot correctly obtain the attribute value of recttransform, resulting in calculation error
- [SUCTF2018]followme
- Shapiro Wilk normal analysis by SPSS
- AttributeError: type object ‘Image‘ has no attribute ‘fromarray‘
- Sum the two numbers to find the target value
- [Fantasy 4] introduction and use of UMG components (under update...)
- Excuse me, is it cost-effective to insure love life patron saint 2.0 increased lifelong life insurance? What are the advantages of this product?
猜你喜欢
js数组常用方法
Flink实时计算topN热榜
Considerations for Apache deploying static web page projects
618再次霸榜的秘密何在?耐克最新财报给出答案
Test -- Summary of interview questions
session-cookie与token
2021-10-04
shell编程01_Shell基础
简洁、快速、节约内存的Excel处理工具EasyExcel
[unity3d] nested use layout group to make scroll view with dynamic sub object height
随机推荐
01 install virtual machine
合并有序数列
2021-09-12
[tutorial] how to make the Helpviewer help document of VisualStudio run independently
VSCode工具使用
PCL之滤波
4. Random variables
2021-09-12
01-spooldir
Session cookies and tokens
数据库字典Navicat自动生成版本
14. Code implementation of semaphore
07 data import sqoop
2021-10-02
Beautiful and intelligent, Haval H6 supreme+ makes Yuanxiao travel safer
Kustomize user manual
Record attributeerror: 'nonetype' object has no attribute 'nextcall‘
SUS系统可用性量表
stm32和电机开发(上位系统)
Sus system availability scale