PAT 甲级 1083 List Grades (25 分)
1083 List Grades (25 分)
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<iostream>
#include<set>
#include<string> using namespace std; struct student
{
string name;
string ID;
int grade; bool operator<(const student stu) const
{
if(grade < stu.grade)
return true;
else
return false;
} bool operator>(const student stu) const
{
if(grade > stu.grade)
return true;
else
return false;
}
}; int main()
{
int N ,flag = ,grade1,grade2;
student stu;
set<student> s; cin>>N; for(int i=;i<N;++i)
{
cin>>stu.name>> stu.ID>>stu.grade; s.insert(stu);
} cin>>grade1>>grade2; set<student>::reverse_iterator begin = s.rbegin(),end = s.rend(),i; for(i=begin;i!=end;++i)
{
if((*i).grade >= grade1 && (*i).grade <= grade2)
{
cout<<i->name<<" "<<i->ID<<endl;
flag = ;
}
} if(flag)
cout<<"NONE"<<endl;
}
PAT 甲级 1083 List Grades (25 分)的更多相关文章
- PAT 甲级 1028 List Sorting (25 分)(排序,简单题)
1028 List Sorting (25 分) Excel can sort records according to any column. Now you are supposed to i ...
- PAT 甲级 1020 Tree Traversals (25分)(后序中序链表建树,求层序)***重点复习
1020 Tree Traversals (25分) Suppose that all the keys in a binary tree are distinct positive intege ...
- PAT 甲级 1146 Topological Order (25 分)(拓扑较简单,保存入度数和出度的节点即可)
1146 Topological Order (25 分) This is a problem given in the Graduate Entrance Exam in 2018: Which ...
- PAT 甲级 1071 Speech Patterns (25 分)(map)
1071 Speech Patterns (25 分) People often have a preference among synonyms of the same word. For ex ...
- PAT 甲级 1063 Set Similarity (25 分) (新学,set的使用,printf 输出%,要%%)
1063 Set Similarity (25 分) Given two sets of integers, the similarity of the sets is defined to be ...
- PAT 甲级 1059 Prime Factors (25 分) ((新学)快速质因数分解,注意1=1)
1059 Prime Factors (25 分) Given any positive integer N, you are supposed to find all of its prime ...
- PAT 甲级 1051 Pop Sequence (25 分)(模拟栈,较简单)
1051 Pop Sequence (25 分) Given a stack which can keep M numbers at most. Push N numbers in the ord ...
- PAT 甲级 1048 Find Coins (25 分)(较简单,开个数组记录一下即可)
1048 Find Coins (25 分) Eva loves to collect coins from all over the universe, including some other ...
- PAT 甲级 1037 Magic Coupon (25 分) (较简单,贪心)
1037 Magic Coupon (25 分) The magic shop in Mars is offering some magic coupons. Each coupon has an ...
随机推荐
- 数据结构与算法之PHP排序算法(希尔排序)
一.基本思想 希尔排序算法是希尔排序,也称递减增量排序算法,是插入排序的一种更高效的改进版本. 该方法的基本思想是:先将整个待排元素序列分割成若干个子序列(由相隔某个“增量”的元素组成的)分别进行直接 ...
- 转载 [c#] 虚函数(Virtual),抽象函数(abstract)和接口的区别
1.virtual:允许被重写,但不强制要求.声明时提供其自身实现: 2.abstract:强制要求其继承者重写.声明时不提供其自身的实现,抽象类不能被实例化: 3.interface:接口就是协议, ...
- 用Eclipse在Weka中嵌入新算法
本文介绍添加一个新算法到Weka集成环境中的过程,并能在GUI中运行并显示其结果.想做到这一点有两种方法,一是用ANT命令生成新的weka.jar(稍后写教程),二是用IDE(Eclipse或NetB ...
- css清除常用默认样式表
/*公共样式*/ html, body, div, ul, li, h1, h2, h3, h4, h5, h6, p, dl, dt, dd, ol, form, input, textarea, ...
- DevExpress.Mvvm.Free
DevExpress MVVM Framework is a set of components helping to work in the Model-View-ViewModel pattern ...
- unity中实现场景之间加载进度条
using UnityEngine; using System.Collections; using UnityEngine.SceneManagement; using UnityEngine.UI ...
- spoj mgame
题解: f[i][j]表示先后手最大差 g[i][j]表示在最大差的时候是否有后手没得走 代码: #include<bits/stdc++.h> using namespace std; ...
- iOS 在工程内部创建一个静态库target
当你在开发项目的时候需要把公用的东西打包出来,其他项目方便使用的时候,打包成静态库是你的最优选择,在工程内部开发的时候新建一个target进行静态库的开发可以使你的开发调试更加方便而不是单独新建一个工 ...
- Python之路,Day9 - 异步IO\数据库\队列\缓存
https://www.cnblogs.com/alex3714/articles/5248247.html http://www.cnblogs.com/wupeiqi/articles/51327 ...
- leetcode python 009
##懒得自己做 ## 验证回文数字int0=63435435print(int(str(int0)[::-1])==int)