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的更多相关文章

  1. PAT (Advanced Level) 1083. List Grades (25)

    简单排序. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...

  2. 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 ...

  3. PTA(Advanced Level)1025.PAT Ranking

    To evaluate the performance of our first year CS majored students, we consider their grades of three ...

  4. PTA (Advanced Level) 1004 Counting Leaves

    Counting Leaves A family hierarchy is usually presented by a pedigree tree. Your job is to count tho ...

  5. PTA (Advanced Level) 1028 List Sorting

    List Sorting Excel can sort records according to any column. Now you are supposed to imitate this fu ...

  6. PTA (Advanced Level) 1020 Tree Traversals

    Tree Traversals Suppose that all the keys in a binary tree are distinct positive integers. Given the ...

  7. 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 ...

  8. 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 ...

  9. PTA (Advanced Level) 1008 Elevator

    Elevator The highest building in our city has only one elevator. A request list is made up with Npos ...

随机推荐

  1. C# Socket 编程 Sample

    使用Socket通信的服务器端编程,熟悉了服务器端和客户端的通信流程,实现了收发信息.文件传送以及震动功能 服务器端先创建Socket,然后将其和本地ip地址以及端口号连接,也就是使用Bind方法,然 ...

  2. Django-事务和锁

    一.事务 1.全局开启事务 在Web应用中,常用的事务处理方式是将每个请求都包裹在一个事务中.这个功能使用起来非常简单,你只需要将它的配置项ATOMIC_REQUESTS设置为True. 它是这样工作 ...

  3. pycharm同一目录下无法import其他文件

    如图:会出现带有红色波浪线,但是确实有random_walk文件 解决方法: 在当前文件下,右键找到mark  Directory as 然后选择source root,完工ok 再如图: 版权声明: ...

  4. 2017 ZSTU寒假排位赛 #5

    题目链接:https://vjudge.net/contest/148901#overview. A题,排序以后xjbg即可. B题,弄个数组记录当前列是不是删除以及当前行是不是已经大于下一行然后乱搞 ...

  5. elasticsearch利用head插件

    restful接口使用方法 RESTful接口URL的格式: http://localhost:9200///[] 其中index.type是必须提供的. id是可选的,不提供es会自动生成. ind ...

  6. 使用聚集索引和非聚集索引对MySQL分页查询的优化

    内容摘录来源:MSSQL123 ,lujun9972.github.io/blog/2018/03/13/如何编写bash-completion-script/ 一.先公布下结论: 1.如果分页排序字 ...

  7. centos7搭建hadoop-2.7.3,zookeeper-3.4.6,hbase-1.2.5(root用户)

    环境:[centos7.hadoop-2.7.3.zookeeper-3.4.6.hbase-1.2.5] 两个节点:[主节点,主机名为Master,用户为root:从节点,主机名为Slave,用户为 ...

  8. ArcGIS中国工具3.0正式发布

    ArcGIS中国工具3.0正式发布,新功能有 1.  支持面积分割(见4.6),见https://weibo.com/tv/v/HsM2ksYY3?fid=1034:4368578107884427 ...

  9. SilverFish

    noHero123/silverfish https://github.com/noHero123/silverfish/blob/master/HrtBddy/instructions.txt Ho ...

  10. 解决Sublime Text3中文显示乱码问题

    一.安装包管理器 使用Ctrl+~快捷键或者通过View->Show Console菜单打开命令行,粘贴如下代码 import urllib.request,os; pf = 'Package ...