1083 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

题目大意:给出n个考生的姓名、id,分数,要求按照分数从高到低排序,并且输出给定分数区间的考生姓名和id。如果不存在满足条件的考生就输出NONE。
分析:将考生按照分数从高到低排序,且题目已经告知不存在分数相等的学生。之后进行输出,若不存在则输出NONE。

cpp 复制代码
#include<algorithm>
#include <iostream>
#include  <cstdlib>
#include  <cstring>
#include   <string>
#include   <vector>
#include   <cstdio>
#include    <queue>
#include    <stack>
#include    <ctime>
#include    <cmath>
#include      <map>
#include      <set>
#define INF 0xffffffff
#define db1(x) cout<<#x<<"="<<(x)<<endl
#define db2(x,y) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<endl
#define db3(x,y,z) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<", "<<#z<<"="<<(z)<<endl
#define db4(x,y,z,r) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<", "<<#z<<"="<<(z)<<", "<<#r<<"="<<(r)<<endl
using namespace std;

typedef struct student
{
    char name[15],id[15];
    int sorce;
}student;

bool cmp(student a,student b)
{
    return a.sorce>b.sorce;
}

int main(void)
{
    #ifdef test
    freopen("in.txt","r",stdin);
    //freopen("in.txt","w",stdout);
    clock_t start=clock();
    #endif //test

    int n,f=0;scanf("%d",&n);
    student num[n+5];
    for(int i=0;i<n;++i)
        scanf("%s%s%d",num[i].name,num[i].id,&num[i].sorce);

    int l,r;scanf("%d%d",&l,&r);
    sort(num,num+n,cmp);
    for(int i=0;i<n;++i)
        if(num[i].sorce>=l&&num[i].sorce<=r)
            f=1,printf("%s %s\n",num[i].name,num[i].id);

    if(!f)printf("NONE\n");

    #ifdef test
    clockid_t end=clock();
    double endtime=(double)(end-start)/CLOCKS_PER_SEC;
    printf("\n\n\n\n\n");
    cout<<"Total time:"<<endtime<<"s"<<endl;        //s为单位
    cout<<"Total time:"<<endtime*1000<<"ms"<<endl;    //ms为单位
    #endif //test
    return 0;
}
相关推荐
圣保罗的大教堂19 小时前
1089 Insert or Merge (25)
pat考试
圣保罗的大教堂4 天前
1081 Rational Sum (20)
pat考试
圣保罗的大教堂8 天前
1074 Reversing Linked List (25)
pat考试
圣保罗的大教堂25 天前
1052 Linked List Sorting (25)
pat考试
圣保罗的大教堂1 个月前
1047 Student List for Course (25)
pat考试
圣保罗的大教堂1 个月前
1028 List Sorting (25)
pat考试
哈哈,柳暗花明1 个月前
软件设计师笔记-数据结构
pat考试
绯樱殇雪2 个月前
编程题 7-29 删除字符串中的子串【PAT】
c++·pat考试
绯樱殇雪2 个月前
编程题 7-14 求整数段和【PAT】
c++·pat考试