当前位置:网站首页>Ranking of grades (Huazhong University of Science and Technology postgraduate examination questions) (DAY 87)
Ranking of grades (Huazhong University of Science and Technology postgraduate examination questions) (DAY 87)
2022-07-30 06:05:00 【Zhang Xueheng】
1:题目
有 N 个学生的数据,Sort student data by grades from low to high,If the grades are the same, they are sorted lexicographically by name characters,If the names are in the same lexicographical order, they are sorted according to the age of the students,并输出 N 个学生排序后的信息.
输入格式
第一行有一个整数 N.
接下来的 N 行包括 N 个学生的数据.每个学生的数据包括姓名(长度不超过 100 的字符串)、年龄(小于等于 100 的正数)、成绩(小于等于 100 的正数).
输出格式
将学生信息按成绩进行排序,成绩相同的则按姓名的字母序进行排序.
然后输出学生信息,按照如下格式:
姓名 年龄 成绩
The alphabetical order of student names is case-sensitive,如 A 要比 a alphabetically first(因为 A 的 ASCII 码比 a 的 ASCII small size).
数据范围
1≤N≤1000
输入样例:
3
abc 20 99
bcd 19 97
bed 20 97
输出样例:
bcd 19 97
bed 20 97
abc 20 99
难度:简单
时/空限制:1s / 64MB
总通过数:904
总尝试数:1426
来源:Huazhong University of Science and Technology postgraduate examination questions
算法标签
2:代码实现
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1010;
int n;
struct Student
{
string name;
int age, score;
bool operator< (const Student& t) const
{
if (score != t.score) return score < t.score;
if (name != t.name) return name < t.name;
return age < t.age;
}
}q[N];
int main()
{
cin >> n;
for (int i = 0; i < n; i ++ )
cin >> q[i].name >> q[i].age >> q[i].score;
sort(q, q + n);
for (int i = 0; i < n; i ++ )
cout << q[i].name << ' ' << q[i].age << ' ' << q[i].score << endl;
return 0;
}
边栏推荐
猜你喜欢
随机推荐
解决没有配置本地nacos但是一直发生localhost8848连接异常的问题
mysql高阶语句(一)
最新版MySQL 8.0 的下载与安装(详细教程)
75. 颜色分类
SQL连接表(内连接、左连接、右连接、交叉连接、全外连接)
MySQL模糊查询性能优化
号称年薪30万占比最多的专业,你知道是啥嘛?
【Koltin Flow(二)】Flow操作符之末端操作符
IDEA的database使用教程(使用mysql数据库)
从字节码角度带你彻底理解异常中catch,return和finally,再也不用死记硬背了
机器学习—梯度下降Gradient Descent Optimization—c语言实现
排列数字(DAY90)dfs
PyCharm使用教程(较详细,图+文)
成绩排序(华中科技大学考研机试题)(DAY 87)
JVM 类加载机制 超详细学习笔记(三)
navicat无法连接mysql超详细处理方法
【图像检测】基于灰度图像的积累加权边缘检测方法研究附matlab代码
[Koltin Flow (2)] The end operator of the Flow operator
What is SOA (Service Oriented Architecture)?
Concurrent Programming Review