Source:

PAT A1083 List Grades (25 分)

Description:

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 [grade1grade2] 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

Keys:

  • 模拟题

Attention:

  • 先筛选,再排序,可以减少时间复杂度

Code:

 /*
Data: 2019-07-13 10:38:02
Problem: PAT_A1083#List Grades
AC: 14:45 题目大意:
按成绩递减打印给定区间内学生的成绩
输入:
第一行给出,人数N
接下来N行,姓名,ID,成绩
最后一行给出,[g1,g2]
输出:
成绩递减,打印姓名和ID
*/
#include<cstdio>
#include<string>
#include<vector>
#include<iostream>
#include<algorithm>
const int M=1e3;
using namespace std;
struct node
{
string name,id;
int grade;
}info[M];
vector<node> ans; bool cmp(node a, node b)
{
return a.grade > b.grade;
} int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif int n,g1,g2;
scanf("%d", &n);
for(int i=; i<n; i++)
cin >> info[i].name >> info[i].id >> info[i].grade;
scanf("%d%d", &g1,&g2);
for(int i=; i<n; i++)
if(info[i].grade>=g1 && info[i].grade<=g2)
ans.push_back(info[i]);
sort(ans.begin(),ans.end(),cmp);
if(ans.size() == )
printf("NONE\n");
for(int i=; i<ans.size(); i++)
cout << ans[i].name << " " << ans[i].id << endl; return ;
}

PAT_A1083#List Grades的更多相关文章

  1. PAT1083:List Grades

    1083. List Grades (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given a l ...

  2. PAT 甲级 1083 List Grades (25 分)

    1083 List Grades (25 分) Given a list of N student records with name, ID and grade. You are supposed ...

  3. A1083. List Grades

    Given a list of N student records with name, ID and grade. You are supposed to sort the records with ...

  4. Taking water into exams could boost grades 考试带瓶水可以提高成绩?

    Takeing a bottle of water into the exam hall could help students boost their grades, researchers cla ...

  5. PAT 1083 List Grades[简单]

    1083 List Grades (25 分) Given a list of N student records with name, ID and grade. You are supposed ...

  6. PAT 甲级 1083 List Grades

    https://pintia.cn/problem-sets/994805342720868352/problems/994805383929905152 Given a list of N stud ...

  7. PAT 1083 List Grades

    #include <cstdio> #include <cstdlib> using namespace std; class Stu { public: ]; ]; }; i ...

  8. pat1083. List Grades (25)

    1083. List Grades (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given a l ...

  9. A1083 List Grades (25)(25 分)

    A1083 List Grades (25)(25 分) Given a list of N student records with name, ID and grade. You are supp ...

随机推荐

  1. java.net.BindException: Address already in use: 解决方法

    java.net.BindException: Address already in use: 解决方法   1. 执行cmd 2. cmd命令模式下输入netstat -ano,然后找到占用端口的那 ...

  2. 如何在原生Android项目里嵌入Cordova

    背景: 这段时间在维护一个Cordova混合项目,以前稍微接触过Cordova,也写过简单的纯纯的Cordova的Demo,但是没有尝试过混合原生的Cordova. 在接到项目后比较了一下项目架构和C ...

  3. win10 打开 sql sever配置管理器

    !找到解决办法啦!WIN10系统 此电脑->右击->管理弹出以上界面啊哈哈哈还有一些解决办法在这个贴吧里...http://tieba.baidu.com/p/3000709047

  4. java中多态的要点

    多态有三要素 继承.方法重写.父类引用指向子类对象 多态可以理解成两个部分:一个是编译时,一个是运行时 编译时:定义规则:运行时:具体实现这个规则. 编译时:把父类强制转换成子类不会报错:运行时:先去 ...

  5. python获取港股通每日成交信息

    接口:ggt_daily 描述:获取港股通每日成交信息,数据从2014年开始 限量:单次最大1000,总量数据不限制 积分:用户积2000积分可调取,5000积分无限制,请自行提高积分,具体请参阅本文 ...

  6. 是否有任何python库可以从自然语言中解析日期和时间?

    我正在寻找的是可以将“明天早上6点”或“中午的下一个模拟”转换为适当的日期时间对象. 解决方案 parsedatetime - 能够解析“人类可读”日期/时间表达式的Python模块. #!/usr/ ...

  7. linux基础文件管理软硬链接

    一.文件系统的基本结构 1.文件和目录被组成一个单根倒置树目录结构 2.文件系统从根目录下开始,用“/”表示 3.根文件系统(rootfs):root filesystem文件名区分大小写 4.以 . ...

  8. Rendering Problems The following classes could not be found:- android.support.v7.internal.app.WindowDecorActionBar (Fix Build Path, Create Class)

    如图出现如下的错误的时候,一般都是升级Androdi Studio 后导致的,引入库不全,或者其他 东西缺少 可以如下解决方案:

  9. 惠普笔记本Ubuntu系统HDMI无输出

  10. 聚合函数 -AVG/MAX/MIN/STDDEV/VARIANCE/SUM/COUNT/MEDIAN

    ------------------------------------------聚合函数--------------------------------------------- --1: AVG ...