当前位置:网站首页>Hdu1236 ranking (structure Sorting)
Hdu1236 ranking (structure Sorting)
2022-07-02 10:55:00 【Woodenman Du】
Topic link http://acm.hdu.edu.cn/showproblem.php?pid=1236
Question
Today's computer test, although there are real-time Ranklist, But the above ranking is only based on the number of completed questions , Not thinking about
Score of each question , So it's not the final ranking . Given the admission score line , Please write a program to find the one who finally passes the score line
examinee , And print their grades in descending order .
Input
The test input contains information about several exams . The second page of each exam information 1 Line gives the number of candidates N ( 0 < N
< 1000 )、 Number of test questions M ( 0 < M < = 10 )、 Fraction line ( Positive integer )G; The first 2 Row sorting gives the number 1 Questions to M The positive integer score of the question ; following N That's ok , Each line gives one
The admission number of candidates ( Length not exceeding 20 String )、 The total number of problems solved by the student m、 And this m The question number of the question
( The title number is from 1 To M).
When the number of candidates enrolled is 0 when , End of input , The exam will not be processed .
Output
For every exam , First, in the first place. 1 The number of candidates whose line output is not lower than the score line n, And then n Row by score from high
To low output online examinee's test number and score , In between 1 The blank space to separate . If more than one candidate has the same score , According to them
The ascending output of number .
Solve
The meaning of the topic is very simple , Calculate the score of each candidate , Find out the candidates who have crossed the line , In descending order of grades 、 The examinee number is output in ascending order .
Here I define a structure of candidate information , And overloaded < Operator , Re borrowing sort Function to sort the structure , It has certain reference value .
AC Code
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int n, m, g, a[11], num, x;
struct Node{
string user; // Examination number
int score; // score
// Custom sort , The scores are in descending order , The test number is in ascending order
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;
// Initialization score
for(int i = 1; i <= n; i++) node[i].score = 0;
// Read in question
for(int i = 1; i <= m; i++) cin >>a[i];
// Read the answers
for(int i = 1; i <= n; i++){
cin >>node[i].user >>num;
// score
while(num--){
cin >>x;
node[i].score += a[x];
}
}
// Sort
sort(node+1, node+1+n);
// Output results
int cnt = 0;
for(int i = 1; i <= n; i++){ // Calculate the number of people passing the line
if(node[i].score >= g) cnt++;
else break;
}
cout <<cnt <<endl;
for(int i = 1; i <= cnt; i++){ // Output data
cout <<node[i].user <<" " <<node[i].score <<endl;
}
}
return 0;
}
边栏推荐
- P1055 [NOIP2008 普及组] ISBN 号码
- What are the popular frameworks for swoole in 2022?
- "Matching" is true love, a new attitude for young people to make friends
- Thanos Receiver
- In the face of uncertainty, the role of supply chain
- Record attributeerror: 'nonetype' object has no attribute 'nextcall‘
- Operator-1初识Operator
- lunix重新分配root 和 home 空间内存
- Lunix reallocates root and home space memory
- JSP webshell免杀——webshell免杀
猜你喜欢
618再次霸榜的秘密何在?耐克最新财报给出答案
互联网快讯:腾讯会议应用市场正式上线;Soul赴港递交上市申请书
[SUCTF2018]followme
使用sqlcipher打开加密的sqlite方法
Retrofit's callback hell is really vulnerable in kotlin synergy mode!
Dialogue Wu Gang: why do I believe in the rise of "big country brands"?
4.随机变量
session-cookie与token
Redis set password
STM32 and motor development (upper system)
随机推荐
In the face of uncertainty, the role of supply chain
数据库字典Navicat自动生成版本
Read H264 parameters from mediarecord recording
简洁、快速、节约内存的Excel处理工具EasyExcel
js promise.all
Open the encrypted SQLite method with sqlcipher
618再次霸榜的秘密何在?耐克最新财报给出答案
UVM - usage of common TLM port
SPSS做Shapiro-Wilk正态分析
Jsp webshell Free from killing - The Foundation of JSP
【AGC】如何解决事件分析数据本地和AGC面板中显示不一致的问题?
使用Windbg静态分析dump文件(实战经验总结)
Mongodb quickly get started with some simple operations of mongodb command line
快速做出原型
使用sqlcipher打开加密的sqlite方法
AI技术产业热点分析
13.信号量临界区保护
Flink实时计算topN热榜
Flink submitter
6种单例模式的实现方式