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 ...
随机推荐
- C++之带有默认参数值的构造函数
在一个类中 ,如果程序员没有写,任何一个构造函数,则编译器将为该类提供一个默认的构造函数,如果程序员对类的构造函数进行了重载,则编译器将不提供默构造函数,这里需要手动书写一个无参的构造函数, 无参的构 ...
- python下vs的使用
part 1:导入pygame包 在python环境下:视图---其他窗口--python环境,选择从pypi安装pygame
- BZOJ 2440 [中山市选2011]完全平方数 二分+容斥
直接筛$\mu$?+爆算?再不行筛素数再筛个数?但不就是$\mu^2$的前缀和吗? 放...怕不是数论白学了$qwq$ 思路:二分+容斥 提交:两次(康了题解) 题解: 首先答案满足二分性质(递增), ...
- Poj 3764 The xor-longest Path(Trie树+xor+贪心)
The xor-longest Path Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6455 Accepted: 1392 ...
- Noip2015 提高组 Day1
T1神奇的幻方 直通 思路: 制定一个lrow记录上一个数字所在的行数,lcolume记录上一个数字所在的列数,然后根据题目的描述进行更改即可 上代码: #include <iostream&g ...
- Oil Deposits (HDU - 1241 )(DFS思路 或者 BFS思路)
转载请注明出处:https://blog.csdn.net/Mercury_Lc/article/details/82706189作者:Mercury_Lc 题目链接 题解:每个点(为被修改,是#)进 ...
- shell之列表的定义与循环
字符串列表定义方法1: a=(f1 f2 f3 f4)for i in ${a[*]}#遍历每一个列表值 for i in ${a[@]}#等价与上一句 实例: #!bin/basha=(f1 f2 ...
- Netfilter 之 钩子函数注册
通过注册流程代码的分析,能够明确钩子函数的注册流程,理解存储钩子函数的数据结构,如下图(点击图片可查看原图): 废话不多说,开始分析: nf_hook_ops是注册的钩子函数的核心结构,字段含义如下所 ...
- 用Python写一个将Python2代码转换成Python3代码的批处理工具
之前写过一篇如何在windows操作系统上给.py文件添加一个快速处理的右键功能的文章:<一键将Python2代码自动转化为Python3>,作用就是为了将Python2的文件升级转换成P ...
- Go语言学习之介绍与环境搭建
Go语言第一课 一.Go语言介绍 1.什么是Go语言? Go 是一个开源的编程语言,它能让构造简单.可靠且高效的软件变得容易. Go是从2007年末由Robert Griesemer, Rob Pik ...