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. 96、搬家到csdn

    大家好: 今天开始会将所有的博客搬家到CSDN,以后请参考CSDN上的博客:http://blog.csdn.net/u012416045 谢谢 维真

  2. Python模块学习之xlrd 读取Excel时传入formatting_info=True报错:NotImplementedError: formatting_info=True not yet implemented

    问题:xlrd读取Excel时传入 formatting_info=True 报错 之前我们使用读取xls文件的时候都是使用的xlrd库,但是这个库只能操作 .xls格式,对于后来的 .xlsx的版本 ...

  3. Struts1.3——文件上传和下载

    1.Struts文件上传 在Web开发中,会经常涉及到文件的上传和下载,比如在注册账户的时候,我们需要上传自己的头像等. 我们可以利用Struts很方便地实现文件的上传. 1.1 开发步骤 现在,假设 ...

  4. interleave two text files with specified lines

    a_file=$1 a_step=$2 b_file=$3 b_step=$4 a_start=1 let a_end=$a_start+$a_step b_start=1 let b_end=$b_ ...

  5. 递归中,调用forEach方法问题

    1 function traverse(objNmae,obj,url){ url = url || objNmae; if(typeof obj === "object" ){ ...

  6. shell编程:字符串练习题string.sh

    string.sh脚本 #!/bin/bash # string="Bigdata process framework is Hadoop,Hadoop is an open source ...

  7. Myeclipse中dtd代码提示

    1.Myeclipse -->窗口 --> 首选项 2.输入xml c,然后添加 3.输入键 例如:http://struts.apache.org/dtds/struts-2.3.dtd ...

  8. connect failed: 127.0.0.1#953: connection refused

    Problem1 : root@jeremy-VirtualBox:/etc/bind# /etc/init.d/bind9 restart * Stopping domain name servic ...

  9. JUnit中Assert简单介绍

    junit中的assert方法全部放在Assert类中,总结一下junit类中assert方法的分类.1.assertTrue/False([String message,]boolean condi ...

  10. DDCTF 北京地铁

    这周打了ddctf,被打成了dd 北京地铁题目给了一张北京地铁图,提示如下:Color Threshold 提示:AES ECB密钥为小写字母提示2:密钥不足位用\0补全提示3:不要光记得隐写不看图片 ...