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 ...
随机推荐
- 小技巧——直接在目录中输入cmd然后就打开cmd命令窗口
直接在目录中输入cmd然后就打开cmd命令窗口
- 在 CentOS 7 上安装 RabbitMQ
RabbitMQ 服务器在安装之前需要安装 erlang. 最新版本的 RabbitMQ 3.8.0 需要 Erlang 21.3 以上的版本支持. 在这里,我们需要在你的 CentOS 中安装 Er ...
- Python面试题: 判断IP地址是否合法
题目: 给出一个字符串, 判断其是否是是合法的IP(IPv4)地址 思路 将字符串按"."分割成4段得到一个列表 逐个判断列表中的字符串是否数字格式并且在0~255之间, 是在新列 ...
- free 内存检测
free打印出的内存信息主要分为两种,一种是安装的内存,一种是用磁盘虚拟的内存,就是这里的Swap,相信装过Linux系统的同学肯定不陌生交换分区,这里Swap大小就是我们分区的时候分配的大小. 下面 ...
- java 网络文件下载(并命中文名)
public void download(HttpServletRequest request, HttpServletResponse response){ //获取服务器文件 String fil ...
- 1.2 JAVA的String类和StringBuffer类
一.String 1.String概念 String不属于基本类型,String是final修饰的是不可改变的,所以你一旦创建了 String 对象,那它的值就无法改变了如果要对String修改使用 ...
- Leetcode题目226.翻转二叉树(简单)
题目描述: 翻转一颗二叉树 示例: 输入: 4 / \ 2 7 / \ / \ 1 3 6 9 输出: 4 / \ 7 2 / \ / \ 9 6 3 1 思路分析: 1)递归,不断交换左右子树,直到 ...
- Netfilter 之 连接跟踪的helper
注册helper nf_conntrack_ftp_init是连接跟踪ftp模块的初始化函数,可以看到其调用了nf_conntrack_helpers_register来注册helper: stati ...
- JS高级_数据类型
1.分类: a.基本(值)类型: * String :任意字符串 * Number :任意数字 * boolean : true/false * undefined :undefined * null ...
- adb命令连接Android模拟器夜神模拟器
1.打开夜神模拟器,打开设置,调成手机模式,初次进入的话,进入设置 - 关于平板电脑 - 版本号,点击版本号5次,可以激活使用开发者模式:打开设置 -> 开发者选项 -> USB调试, 打 ...