A1083 List Grades (25)(25 分)
A1083 List Grades (25)(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
AC代码
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#define maxn 50
struct Student {
char name[11];
char id[11];
int grade;
}stu[maxn];
int cmp(const void*a, const void*b) {
// struct Student*aa=(Student*)a;
// struct Student*bb=(Student*)b;
struct Student*aa=a;
struct Student*bb=b;
return aa->grade < bb->grade ? 1:-1;//为实现成绩降序,c++ 是>,c语言则是<,1<2返回正值,1==2返回0,1>2,返回负值
}
int main() {
int n, left, right;
scanf("%d", &n);
for(int i = 0; i < n; i++) {
scanf("%s %s %d", stu[i].name, stu[i].id, &stu[i].grade);
}
scanf("%d%d", &left, &right);
qsort(stu,n,sizeof(stu[0]), cmp);
bool flag = false;
for(int i = 0; i < n; i++) {
if(stu[i].grade >= left && stu[i].grade <= right) {
printf("%s %s\n", stu[i].name, stu[i].id);
flag = true;
}
}
if(flag == false) {
printf("NONE\n");
}
return 0;
}
A1083 List Grades (25)(25 分)的更多相关文章
- PAT 甲级 1083 List Grades (25 分)
1083 List Grades (25 分) Given a list of N student records with name, ID and grade. You are supposed ...
- 怎么设置BarTender中二维码大小为25*25
有小伙伴近期问了小编一个问题,说客户需要25*25大小的QR Code二维码,用BarTender怎么做出来?想要指定条形码的大小,还得BarTender符号与版本选项来帮忙.本文小编就来给大家详细讲 ...
- JAVA题目:正整数n若是其平方数的尾部,则称n为同构数 如:5*5=25, 25*25=625 问: 求1~99中的所有同构数
1 /*题目:正整数n若是其平方数的尾部,则称n为同构数 2 如:5*5=25, 25*25=625 3 问: 求1~99中的所有同构数 4 */ 5 //分析:将1-99分为1-9和10-99,用取 ...
- A1083 List Grades (25 分)
Given a list of N student records with name, ID and grade. You are supposed to sort the records with ...
- [C++]PAT乙级1010. 一元多项式求导 (25/25)
/* 1010. 一元多项式求导 (25) 设计函数求一元多项式的导数.(注:x^n(n为整数)的一阶导数为n*x^n-1.) 输入格式: 以指数递降方式输入多项式非零项系数和指数(绝对值均为不超过1 ...
- [C++]PAT乙级1005. 继续(3n+1)猜想 (25/25)
/* 1005. 继续(3n+1)猜想 (25) 卡拉兹(Callatz)猜想已经在1001中给出了描述.在这个题目里,情况稍微有些复杂. 当我们验证卡拉兹猜想的时候,为了避免重复计算,可以记录下递推 ...
- A1083. List Grades
Given a list of N student records with name, ID and grade. You are supposed to sort the records with ...
- PAT甲级——A1083 List Grades
Given a list of N student records with name, ID and grade. You are supposed to sort the records with ...
- PAT 甲级 1006 Sign In and Sign Out (25)(25 分)
1006 Sign In and Sign Out (25)(25 分) At the beginning of every day, the first person who signs in th ...
随机推荐
- Editplus配置java编译环境
EditPlus配置java编译环境 第一步:检测自己是否已经有jdk 1.win+r,输入cmd,打开控制台 2.控制台下输入javac出现类似的画面,代表jdk已经成功安装 第二步:打开Editp ...
- ORA-02298: 无法验证 (约束) - 未找到父项关键字 解决办法
--在用PL/SQL导入表数据的时候报错 ORA-02298: 无法验证 (PNET.POST_CLOB_FK) - 未找到父项关键字 --发现是启用外键约束时报的错alter table DM_VO ...
- Sql server 数据库的备份和还原数据库提示“ 加载的介质已格式化为支持 1 个介质簇,但根据指定的备份设备,应支持 2 个介质簇”
数据库备份和还原总结 在 "M:\2017-Pro\company\other\databak_2014-10\anquanbaowei_db_201704300200.BAK" ...
- mybatis批量插入插入数据、批量条件查询
ps:参考文章连接:https://www.cnblogs.com/admol/articles/4248159.html 关于个人的使用经验:先把数据放到bean中,多个的话就全放入list集合,如 ...
- css3的transform变换scale和translate等影响jQuery的position().top和offset().top
css3的transform变换scale和translate等影响jQuery的position().top和offset().top
- es6-异步应用
异步编程对 JavaScript 语言太重要.Javascript 语言的执行环境是“单线程”的,如果没有异步编程,根本没法用,非卡死不可.本章主要介绍 Generator 函数如何完成异步操作. 传 ...
- css3动画-加载中...
写几个简单的加载中动画吧. 像前面三种都是相当于几个不同的点轮流来播放同一动画:变大变小.css3里面有一个用于尺度变换的方法:scale(x,y):定义 2D 缩放转换,改变元素的宽度和高度. 第四 ...
- 常用CSS3属性整理
常用CSS3属性整理 文本 文本超出部分折叠 white-space:nowarp; overflow:hidden; text-overflow:ellipsis word-warp 边界换行 no ...
- alias 新的命令='原命令 -选项/参数'。举例说明,alias l=‘ls -lsh' 将重新定义 ls 命令,现在只需输入 l 就可以列目录了。
alias 新的命令='原命令 -选项/参数'.举例说明,alias l=‘ls -lsh' 将重新定义 ls 命令,现在只需输入 l 就可以列目录了.
- Git 推送和删除标签
事实上Git 的推送和删除远程标签命令是相同的,删除操作实际上就是推送空的源标签refs:git push origin 标签名相当于git push origin refs/tags/源标签名:re ...