A1083 List Grades (25 分)
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
开始技术总结:
第一点就是初始化数组或是结构体的时候,大小要用常量,不能够使用输入量初始化
还有就是中文的括号注意一点
参考代码:
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 50;
struct Student {
char ID[11];
char name[11];
int grade;
}student[MAXN];
bool cmp(Student a, Student b) {
if (a.grade != b.grade) return a.grade > b.grade;
}
int main(){
int grade1, grade2;
int N;
scanf("%d", &N);
for (int i = 0; i < N; i++) {
scanf("%s%s%d", student[i].name, student[i].ID, &student[i].grade);
}
scanf("%d%d", &grade1, &grade2);
sort(student, student + N, cmp);
int flag = 0;//用来标记是否又符合条件的同学,0表示没有
for (int j = 0; j < N; j++) {
if (student[j].grade <= grade2 && student[j].grade >= grade1) {
printf("%s %s\n", student[j].name, student[j].ID);
flag = 1;
}
}
if (flag == 0) {
printf("NONE");
}
system("pause");
return 0;
}
A1083 List Grades (25 分)的更多相关文章
- 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 ...
- 【PAT甲级】1083 List Grades (25 分)
题意: 输入一个正整数N(<=101),接着输入N个学生的姓名,id和成绩.接着输入两个正整数X,Y(0<=X,Y<=100),逆序输出成绩在x,y之间的学生的姓名和id. tric ...
- PAT 甲级 1083 List Grades (25 分)
1083 List Grades (25 分) Given a list of N student records with name, ID and grade. You are supposed ...
- 1012 The Best Rank (25 分)
1012 The Best Rank (25 分) To evaluate the performance of our first year CS majored students, we cons ...
- 1062 Talent and Virtue (25 分)
1062 Talent and Virtue (25 分) About 900 years ago, a Chinese philosopher Sima Guang wrote a history ...
- 1036 Boys vs Girls (25 分)
1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade of ...
- A1012 The Best Rank (25)(25 分)
A1012 The Best Rank (25)(25 分) To evaluate the performance of our first year CS majored students, we ...
- PATA1012The Best Rank(25分)
To evaluate the performance of our first year CS majored students, we consider their grades of three ...
- PAT 甲级 1062 Talent and Virtue (25 分)(简单,结构体排序)
1062 Talent and Virtue (25 分) About 900 years ago, a Chinese philosopher Sima Guang wrote a histor ...
随机推荐
- iframe嵌套页面中的跳转
简单说一下场景. 假设有A.B.C和D四个JSP页面,D通过iframe嵌套在C中,C通过iframe嵌套在B中,B通过iframe嵌套在A中. 然后现在在D中编写JavaScript代码跳转页面. ...
- jwt入门
JWT(JSON Web Token)是一个非常轻巧的规范,这个规范允许我们使用JWT在用户和服务器之间传递安全可靠的信息,通常使用在HTTP通信过程中进行身份认证. 我们知道,HTTP通信是无状态的 ...
- 搜索旋转排序数组II
题目 假设按照升序排序的数组在预先未知的某个点上进行了旋转. ( 例如,数组 [,,,,,,] 可能变为 [,,,,,,] ). 编写一个函数来判断给定的目标值是否存在于数组中.若存在返回 true, ...
- m3u8的blob格式视频在线下载
有时候我们希望在在线观看视频的同时将对应的视频下载下来,研究了很多方式,最终发现使用ffmpeg这个工具可以很好完成m3u8格式. 具体方法就是执行: ffmpeg -i https://cdn-ho ...
- Python【day 10】函数进阶-动态函数
形参小结 1.位置参数2.默认值参数3.动态参数 1.*args 位置参数的动态传参. 系统会自动的把所有的位置参数聚合成元组 2.**kwargs 关键字参数的动态传参. 系统会自动的把所有的关键字 ...
- SQLAlchemy--基本增删改查
目录 简介 安装 组成部分 简单使用 执行原生sql(不常用) orm使用(重点) 常用数据类型 Column常用参数 常用操作(CURD) 创建映射类的实例 创建会话Session 增加add()/ ...
- JavaScript Location 对象用法
Location 对象 Location对象包含有关当前URL的信息.location对象是window对象的一部分,可以通过window.location属性访问. 注意:没有适用于location ...
- php取整的几种方式,四舍五入,舍去法取整,进一法取整
php取整的几种方式,四舍五入,舍去法取整,进一法取整方式一:round 对浮点数进行四舍五入语法:float round ( float val [, int precision] ) echo r ...
- Seata为什么效率高
1. Seata为什么效率高 1.1. 应对面试官的解释 Seata的解决方案是两阶段提交的升级版,传统两阶段提交资源管理器(RM)放在数据库端,由数据库管理,需要数据库支持XA协议. 而Seata把 ...
- android studio学习----gradle命令详解
首先来给大家介绍一种简便并且个人最喜欢的一种办法.很多时候我们在GitHub上看到一个不错的开源项目,一般有两种需求,阅读源码和查看运行效果,如果是单纯的查看源码我更喜欢用一些轻量级编辑器,如vim, ...