PTA(Advanced Level)1083.List Grades
Given a list of N student records with name, ID and grade. You are supposed to sort the records with respect to the grade in non-increasing order, and output those student records of which the grades are in a given interval.
Input Specification:
Each input file contains one test case. Each case is given in the following format:
N
name[1] ID[1] grade[1]
name[2] ID[2] grade[2]
... ...
name[N] ID[N] grade[N]
grade1 grade2
where name[i] and ID[i] are strings of no more than 10 characters with no space, grade[i] is an integer in [0, 100], grade1 and grade2 are the boundaries of the grade's interval. It is guaranteed that all the grades are distinct.
Output Specification:
For each test case you should output the student records of which the grades are in the given interval [grade1, grade2] and are in non-increasing order. Each student record occupies a line with the student's name and ID, separated by one space. If there is no student's grade in that interval, output NONE instead.
Sample Input 1:
4
Tom CS000001 59
Joe Math990112 89
Mike CS991301 100
Mary EE990830 95
60 100
Sample Output 1:
Mike CS991301
Mary EE990830
Joe Math990112
Sample Input 2:
2
Jean AA980920 60
Ann CS01 80
90 95
Sample Output 2:
NONE
思路
- 用结构体数组存储数据,一次排序之后+一次遍历输出符合条件的人的信息就好了
代码
#include<bits/stdc++.h>
using namespace std;
struct student
{
string name, id;
int grade;
}a[10010];
bool cmp(student a, student b)
{
return a.grade < b.grade;
}
int main()
{
int n;
cin >> n;
for(int i=0;i<n;i++)
cin >> a[i].name >> a[i].id >> a[i].grade;
sort(a, a+n, cmp);
int l, r;
bool finded = false; //表示是否至少有一个输出
cin >> l >> r;
if(l > r) swap(l,r);
for(int i=n-1;i>=0;i--) //题目要求的是分数按高到低排,所以倒过来遍历
{
if(a[i].grade >= l && a[i].grade <= r)
{
finded = true;
cout << a[i].name << " " << a[i].id << endl;
}
}
if(!finded)
cout << "NONE";
return 0;
}
引用
https://pintia.cn/problem-sets/994805342720868352/problems/994805383929905152
PTA(Advanced Level)1083.List Grades的更多相关文章
- PAT (Advanced Level) 1083. List Grades (25)
简单排序. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...
- PTA(Advanced Level)1036.Boys vs Girls
This time you are asked to tell the difference between the lowest grade of all the male students and ...
- PTA(Advanced Level)1025.PAT Ranking
To evaluate the performance of our first year CS majored students, we consider their grades of three ...
- PTA (Advanced Level) 1004 Counting Leaves
Counting Leaves A family hierarchy is usually presented by a pedigree tree. Your job is to count tho ...
- PTA (Advanced Level) 1028 List Sorting
List Sorting Excel can sort records according to any column. Now you are supposed to imitate this fu ...
- PTA (Advanced Level) 1020 Tree Traversals
Tree Traversals Suppose that all the keys in a binary tree are distinct positive integers. Given the ...
- PTA (Advanced Level) 1012 The Best Rank
The Best Rank To evaluate the performance of our first year CS majored students, we consider their g ...
- PTA (Advanced Level) 1009 Product of Polynomials
1009 Product of Polynomials This time, you are supposed to find A×B where A and B are two polynomial ...
- PTA (Advanced Level) 1008 Elevator
Elevator The highest building in our city has only one elevator. A request list is made up with Npos ...
随机推荐
- 公共钥匙盒(CCF)【模拟】
问题描述 有一个学校的老师共用N个教室,按照规定,所有的钥匙都必须放在公共钥匙盒里,老师不能带钥匙回家.每次老师上课前,都从公共钥匙盒里找到自己上课的教室的钥匙去开门,上完课后,再将钥匙放回到钥匙盒中 ...
- 路由器配置——路由重分布1(rip)
一.实验目的:使用路由重分布达到全网互通 二.拓扑图: 三.具体实验步骤配置 先给各个主机配置ip地址和网关以PC1为例: (1)R1路由器配置 Router>enable --进入特权模式R ...
- CentOS7从一般用户切换到root用户
可以使用如下命令从普通用户切换到root用户: su root 键入回车后,系统提示输入密码(此密码即你平时使用的那个用户的密码.关于这一点我还没有确定是否所有用户都可以切换到root用户身份).验证 ...
- Java线程间如何通信(五)
1.简述 线程是操作系统中独立的个体,但这些个体如果不经过特殊的处理就不能称为一个整体. 使线程之间进行通信后,在大大提高CPU利用率的同时还会使开发人员对各个线程任务在处理的过程中进行有效的把控. ...
- 如何使用SendGrid发送邮件
特别提示:本人博客部分有参考网络其他博客,但均是本人亲手编写过并验证通过.如发现博客有错误,请及时提出以免误导其他人,谢谢!欢迎转载,但记得标明文章出处:http://www.cnblogs.com/ ...
- 使用arcpy.mapping 更新和修复数据源
来自:https://blog.csdn.net/gisinfo/article/details/6675390 在许多情况下,您都可能需要修复数据源或重定向数据源至其他位置.然而,如果是在每个相关的 ...
- SpringBoot几种定时任务的实现方式 和多线程执行任务
定时任务实现的几种方式: Timer:这是java自带的java.util.Timer类,这个类允许你调度一个java.util.TimerTask任务.使用这种方式可以让你的程序按照某一个频度执行, ...
- 02 MySQL之数据表的基本操作
01-创建数据表 # 切换数据库 use test_db; # 创建数据表 语法规则如下: create table 表名 ( 字段名1, 数据类型 [列级别约束条件] [默认值], 字段名2, 数据 ...
- 小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_5-4.微信授权一键登录开发之授权URL获取
笔记 4.微信授权一键登录开发之授权URL获取 简介:获取微信开放平台扫码连url地址 1.增加结果工具类,JsonData; 增加application.properties配置 ...
- Java SpringBoot React Redux
1.字符串转换相关 - React 前端JS部分 JSON.parse(JSON.stringify(copyRow)); 2.字符串分隔相关,弹出confirm确认框,显示换行信息 - React ...