PAT_A1083#List Grades
Source:
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]
andID[i]
are strings of no more than 10 characters with no space,grade[i]
is an integer in [0, 100],grade1
andgrade2
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, outputNONE
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 ;
}
最新文章
- mybatis一个怪异的问题: Invalid bound statement not found
- 论Linux运维的一些基础安全知识和简单办法
- utime函数
- BestCoder18 1002.Math Problem(hdu 5105) 解题报告
- SQLAlchemy 对象缓存和刷新
- C# Winform DataGridView分页功能的实现
- nginx rewrite 参数和例子
- Unit Testing PowerShell Code with Pester
- MongoDB入门(1)--安装配置
- Thread.sleep还是TimeUnit.SECONDS.sleep
- Yii --Command 任务处理
- 买面包和IoC
- 深入理解SQL的四种连接
- centos 下 安装mysql
- 【Hdu2089】不要62(数位DP)
- Django学习日记01_环境搭建
- 转:彻底搞清referrer和origin
- 《JAVA程序设计》_第八周学习总结
- go 语言图片像素点处理
- 全国青少年信息学奥林匹克分区联赛(N)竞赛大纲