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. 路由器配置——路由重分布2(OSPF)

    一.实验目的:使用路由重分布达到全网互通的效果 二.拓扑图: 三.具体步骤配置: 1.先给各台主机配置ip地址及网关,以PC1为例: 2.路由器配置: (1)R1路由器配置 Router>ena ...

  2. HGOI 20191108 题解

    Problem A 新婚快乐 一条路,被$n$个红绿灯划分成$n+1$段,从前到后一次给出每一段的长度$l_i$,每走$1$的长度需要$1$分钟. 一开始所有红绿灯都是绿色的,$g$分钟后所有红绿灯变 ...

  3. codeforces#1183F. Topforces Strikes Back(数论)

    题目链接: http://codeforces.com/contest/1183/problem/F 题意: 给出n个数,找出最多三个互不整除的数,取最大的和 数据范围: $1 \le n \le 2 ...

  4. 来谈谈MySQL的临时表,到底是个什么东西,以及怎么样产生的

    介绍临时表之前,我们首先来看这么一句语句: CREATE TABLE `words` ( `id` ) NOT NULL AUTO_INCREMENT, `word` ) DEFAULT NULL, ...

  5. div设置百分比高度 宽度

    给div按百分比设置高度 宽度两种方法: 第一种是给body标签设置他的高度值,xxxpx,div就会根据body的像素值取百分比: 第二种方法就是在div属性中加入 position:absolut ...

  6. 递推,求至少连续放置三个U的危险组合

    UVA580-Critical Mass 题意 有两种方块,L和U,有至少三个连续的U称为危险组合,问有多少个危险组合 solution: 至少这个概念比较难求 ,所以转化为(1ll<<n ...

  7. LeetCode 10. 正则表达式匹配(Regular Expression Matching)

    题目描述 给定一个字符串 (s) 和一个字符模式 (p).实现支持 '.' 和 '*' 的正则表达式匹配. '.' 匹配任意单个字符. '*' 匹配零个或多个前面的元素. 匹配应该覆盖整个字符串 (s ...

  8. 编译安装 Nginx

    一.下载 https://nginx.org/en/download.html yum install -y wget wget http://nginx.org/download/nginx-1.1 ...

  9. WordPress窗体化侧边栏

    窗体化侧边栏是一个支持 Widget 的侧边栏或者说是窗体化(widgetized)的侧边栏几乎是 WordPress 主题的标准. 首先,什么是窗体化(widgetizing)呢?简单的说,窗体化就 ...

  10. tensorflow自动写诗

    1.目录结构 2.入口类 # coding = utf-8 """ 注意:RNN使用的数据为序列化的数据 RNN网络:主要由多个LSTM计算单元组成,依靠BPTT算法进行 ...