首页 > 编程语言 >PAT_Advanced Level_1083 List Grades (25分)(C++_快排)

PAT_Advanced Level_1083 List Grades (25分)(C++_快排)

时间:2023-06-20 10:06:23浏览次数:78  
标签:25 1083 name Level grade int student records ID


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

Process

这种题应该没啥说的吧,英文简单,做起来更简单。

Code

#include<bits/stdc++.h>
using namespace std;
struct student {
	string name, id;
	int grade;
};
int n;
bool cmp(student a, student b)
{
	return a.grade >= b.grade;
}
int main()
{
	cin >> n;
	vector<student> vt, vr;
	for (int i = 0; i < n; i++) {
		student a;
		cin >> a.name >> a.id >> a.grade;
		vt.push_back(a);
	}
	int low, high;
	cin >> low >> high;
	for (int i = 0; i < n; i++)
		if (vt[i].grade <= high && vt[i].grade >= low)
			vr.push_back(vt[i]);
	if (vr.empty())
		cout << "NONE";
	else {
		sort(vr.begin(), vr.end(), cmp);
		for (int i = 0; i < vr.size(); i++)
			cout << vr[i].name << " " << vr[i].id << endl;
	}
	return 0;
}


标签:25,1083,name,Level,grade,int,student,records,ID
From: https://blog.51cto.com/u_16165815/6520481

相关文章

  • PAT (Advanced Level)_1100 Mars Numbers (20分)(C++_模拟)
    PeopleonMarscounttheirnumberswithbase13:ZeroonEarthiscalled"tret"onMars.Thenumbers1to12onEarthiscalled"jan,feb,mar,apr,may,jun,jly,aug,sep,oct,nov,dec"onMars,respectively.Forthenexthigherdigi......
  • PAT_Advanced Level_1080 Graduate Admission(C++_模拟_快排_卡常)
    Itissaidthatin2011,thereareabout100graduateschoolsreadytoproceedover40,000applicationsinZhejiangProvince.Itwouldhelpalotifyoucouldwriteaprogramtoautomatetheadmissionprocedure.Eachapplicantwillhavetoprovidetwograd......
  • PAT_Advanced Level_1078 Hashing (25分)(C++_Hush_平方探测法)
    Thetaskofthisproblemissimple:insertasequenceofdistinctpositiveintegersintoahashtable,andoutputthepositionsoftheinputnumbers.ThehashfunctionisdefinedtobeH(key)=key%TSizewhereTSizeisthemaximumsizeofthehashtable.Qu......
  • nginx 1.25. 1 发布
    nginx1.25.1有一个很不错的特性,就是支持了http2指令,以前这个指令主要是也listen配置使用的(ssl+http2场景)独立指令之后就有了很方便的功能了,比如有些业务希望使用http0.9-1.1协议,有些需要使用http2,当然目前也是支持了http3的,可以做到分离,以前版本存在一个问题就是开启了......
  • 阶段性知识总结解释版【Day01-Day25】
    day021.什么是编程和编程语言编程 是指使用计算机语言编写计算机程序的过程。编程语言 是一种用于编写计算机程序的形式化语言,它可以被解释器或编译器转换成机器码以便计算机执行。编程语言包括C、Java、Python、JavaScript、PHP等。2.计算机五大组成部分,分别阐释一......
  • 阶段性知识总结习题版【Day01-Day25】
    day02什么是编程和编程语言计算机五大组成部分,分别阐释一下各自特点计算机三大核心硬件,各自的特点常见的操作系统day03计算机存储数据的单位有哪些,之间的单位换算是怎样的编程语言的发展史,分别有什么特点编程语言的分类python解释器的版本有哪些,推荐使用的版本是哪个......
  • RT-THREAD的SFUD驱动简介基于W25Q128
    SFUD简介SFUD是一款开源的串行SPIFlash通用驱动库。详细介绍可查看官方说明,作为一个通用的中间套件,帮用户屏蔽了底层的FLASH操作,也方便用户使用不同的FLASH时进行移植。只需要配置好SPI就可以完成驱动的移植。FLASH特点FLASH写的时候,只能从1写到0,而不能从0写到1。因此写之......
  • 智能佳—LoCoBot WX250 6自由度 (用于科研与教学的ROS智能车)
    LoCoBot是用于映射、导航和操纵(可选)等ROS研究的智能车,研究人员、教育工作者和学生都可以使用LoCoBot专注于高级代码的开发,而不是专注硬件和构建低级代码。通过开放的源代码软件、完整的ROS映射和导航包以及模块化的开放源代码PythonAPI,LoCoBot上的开发得以简化,用户仅需10行代码......
  • DB 从关闭数据库 看看你在那个LEVEL
    关闭数据库,呵呵,看上去没有什么可以说的,或者说没有什么技术含量,属于只要脖子上有一双带眼睛的脑袋就可以进行操作.事实是这样的吗?  关闭数据库看似简单的事情也能给评出个  369等的LEVEL.什么LEVEL 从关闭数据库中体现你对整体数据库系统操作和认知的LEVEL到底有没有......
  • 从3000ms到25ms!看看人家的接口优化技巧,确实很优雅!!
    批处理避免多次IO异步处理空间换时间使用缓存预处理预计算池化思想数据库连接池,线程池。避免重复创建与销毁。优化程序结构程序经过多次迭代,多人维护开发情况下,会出现一些重复操作等等。串行改并行索引加索引,排除索引失效场景避免大事务......