当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
随机推荐
Database dictionary Navicat automatic generation version
集成学习概览
SUS系统可用性量表
[unity3d] cannot correctly obtain the attribute value of recttransform, resulting in calculation error
数据库字典Navicat自动生成版本
UVM - usage of common TLM port
面对不确定性,供应链的作用
Oracle notes
In the face of uncertainty, the role of supply chain
Oracle 笔记
flume 190 INSTALL
LeetCode+ 76 - 80 暴搜专题
What is the significance of the college entrance examination
stm32和電機開發(上比特系統)
Mongodb quickly get started with some simple operations of mongodb command line
PCL 投影点云
MySQL lethal serial question 3 -- are you familiar with MySQL locks?
js promise.all
flume 190 INSTALL
14.信号量的代码实现




![2. Hacking lab script off [detailed writeup]](/img/f3/29745761cd5ad4df84c78ac904ea51.png)




