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 ;
}

最新文章

  1. mybatis一个怪异的问题: Invalid bound statement not found
  2. 论Linux运维的一些基础安全知识和简单办法
  3. utime函数
  4. BestCoder18 1002.Math Problem(hdu 5105) 解题报告
  5. SQLAlchemy 对象缓存和刷新
  6. C# Winform DataGridView分页功能的实现
  7. nginx rewrite 参数和例子
  8. Unit Testing PowerShell Code with Pester
  9. MongoDB入门(1)--安装配置
  10. Thread.sleep还是TimeUnit.SECONDS.sleep
  11. Yii --Command 任务处理
  12. 买面包和IoC
  13. 深入理解SQL的四种连接
  14. centos 下 安装mysql
  15. 【Hdu2089】不要62(数位DP)
  16. Django学习日记01_环境搭建
  17. 转:彻底搞清referrer和origin
  18. 《JAVA程序设计》_第八周学习总结
  19. go 语言图片像素点处理
  20. 全国青少年信息学奥林匹克分区联赛(N)竞赛大纲

热门文章

  1. 56、salesforce学习笔记(三)
  2. upc组队赛6 Bumped!【最短路】
  3. IOU计算python实现
  4. Java构造函数(构造器)
  5. Oracle启动或关闭归档模式
  6. input输入框数字转带千分位的字符串
  7. 使用sass
  8. postgresql 取出分组中最大的几条数据
  9. teb教程2
  10. JAVA企业级应用服务器之TOMCAT实战