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 ...
随机推荐
- nginx图片缓存服务器配置实战
1.图片目录设置: 假定服务器主目录为nginx的默认目录:/usr/local/nginx-0.8.32/html/ 图片存放目录为:/usr/local/nginx-0.8.32/html/SD ...
- 如何去除Discuz标题栏中的Powered by Discuz!
今天修改discuz代码遇到一个问题,就是标题栏中的Powered by Discuz!,很不美观.查资料后得到了解决方法!介绍给大家. 那么如何去掉标题里面的Powered by Discuz!呢? ...
- SQLServer数据库语句大全汇总
目录清单CONTEXT LIST1.数据库DataBase 1.1数据库建立/删除create/drop database 1.2数据库备份与恢复backup/restore database2.数据 ...
- Aspx 验证码_各种封装
验证码 namespace CZBK.TestProject.Common { public class ValidateCode { public ValidateCode() { } /// &l ...
- Sql Server 2012 存储过程的单步调试
最近在做vb项目的时候,用到了存储过程的调试,现在总结一下发现单步调试存储过程有以下2种方法: 1.这种方法自己已经做过,是可以的,如下: a.如果目标数据库存在存储过程,右击该存储过程-修改,打开存 ...
- Openstack Ocata 多节点分布式部署
1 安装环境 1.1 安装镜像版本 建议最小化安装,这里用的是CentOS-7-x86_64-Minimal-1511. 1.2 网络规划 本文包含控制节点controller3,计算节点comput ...
- table-列组
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 关于在C++中调用system函数
先看看下面的这一段程序: #include <iostream> #include <cstdlib> int main(int argc, char* argv[]) { s ...
- 【extjs6学习笔记】1.13 初始: 模型
Ext JS包括数据包Ext.data包括处理从服务器保存和检索数据的类. 以下是Ext JS 6数据包中的重要类: Model (Ext.data.Model) Store (Ext.data.St ...
- gitlab用户添加ssh免密钥认证后clone还是要求输入密码
今天在centos 7公网服务器上安装gitlab在配置ssh免密钥时遇到一个奇怪的事,正确添加了本机的公钥到gitlab账户上,进行clone时死活都要你输入密码gitlab使用yum安装的,之前在 ...