当前位置:网站首页>成绩排序(华中科技大学考研机试题)(DAY 87)
成绩排序(华中科技大学考研机试题)(DAY 87)
2022-07-30 05:26:00 【张学恒】
1:题目
有 N 个学生的数据,将学生数据按成绩从低到高排序,如果成绩相同则按姓名字符的字典序排序,如果姓名的字典序也相同则按照学生的年龄从小到大排序,并输出 N 个学生排序后的信息。
输入格式
第一行有一个整数 N。
接下来的 N 行包括 N 个学生的数据。每个学生的数据包括姓名(长度不超过 100 的字符串)、年龄(小于等于 100 的正数)、成绩(小于等于 100 的正数)。
输出格式
将学生信息按成绩进行排序,成绩相同的则按姓名的字母序进行排序。
然后输出学生信息,按照如下格式:
姓名 年龄 成绩
学生姓名的字母序区分字母的大小写,如 A 要比 a 的字母序靠前(因为 A 的 ASCII 码比 a 的 ASCII 码要小)。
数据范围
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
来源:华中科技大学考研机试题
算法标签
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;
}
边栏推荐
- go language study notes 4
- 【Redis高手修炼之路】Jedis——Jedis的基本使用
- 是时候不得不学英语了,技多不压身,给自己多条路
- Hexagon_V65_Programmers_Reference_Manual (12)
- Thymeleaf简介
- 工作效率-十五分钟让你快速学习Markdown语法到精通排版实践备忘
- The use of Conluce, an online document management system
- 力扣1047-删除字符串中的所有相邻重复项——栈
- MySQL索引常见面试题(2022版)
- Summary of skills in using ms project2010 project management software
猜你喜欢

The Golden Circle Rule: Deep Thinking Methods for Successful People

给小白的 PG 容器化部署教程(下)

RadonDB MySQL Kubernetes 2.2.0 发布!

参与开源,让程序员找回热血和激情

Internet (software) company project management software research report

22-07-29 西安 分布式事务、Seata

程序员赚钱实操,手把手教你做付费课程,自媒体,付费文章及付费技术课赚钱

idea 编译protobuf 文件的设置使用

一个老程序员的2020年总结回顾,2021年如何变的更牛逼

力扣05-替换空格——字符串问题
随机推荐
Unity stepping on the pit record - the use of GetComponent
curl (7) Failed connect to localhost8080; Connection refused
美国再次加息75个基点 陷入“技术性衰退”?加密市场却呈现复苏力量
2022鹏城杯web
路径依赖:穷人很难逆袭突破的科学道理
Hexagon_V65_Programmers_Reference_Manual (10)
工作效率-十五分钟让你快速学习Markdown语法到精通排版实践备忘
[Verilog] HDLBits Problem Solution - Circuits/Combinational Logic
容器化 | 在 K8s 上部署 RadonDB MySQL Operator 和集群
Us to raise interest rates by 75 basis points in "technical recession"?Encryption market is recovering
翻译 | 解读首部 Kubernetes 纪录片
JVM 内存结构 超详细学习笔记(一)
力扣541-反转字符串2——双指针法
(Hexagon_V65_Programmers_Reference_Manual(13)
是时候不得不学英语了,技多不压身,给自己多条路
RadonDB MySQL on K8s 2.1.4 发布!
IIS网站出现401未授权访问
pycharm上的tensorflow环境搭载
An old programmer's summary review of 2020, how to become more awesome in 2021
This article will take you through js to deal with the addition, deletion, modification and inspection of tree structure data