• PAT 甲级 1083 List Grades (25 分)


    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 [grade1grade2] 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



     1 #include<iostream>
     2 #include<set>
     3 #include<string>
     4 
     5 using namespace std;
     6 
     7 struct student
     8 {
     9   string name;
    10   string ID;
    11   int grade;
    12   
    13   bool operator<(const student stu) const
    14   {
    15     if(grade < stu.grade)
    16       return true;
    17     else
    18       return false;
    19   }
    20   
    21   bool operator>(const student stu) const
    22   {
    23     if(grade > stu.grade)
    24       return true;
    25     else
    26       return false;
    27   }
    28 };
    29 
    30 int main()
    31 {
    32   int N ,flag = 1,grade1,grade2;
    33   student stu;
    34   set<student> s;
    35   
    36   cin>>N;
    37   
    38   for(int i=0;i<N;++i)
    39   {
    40     cin>>stu.name>> stu.ID>>stu.grade;
    41     
    42     s.insert(stu);
    43   }
    44   
    45   cin>>grade1>>grade2;
    46   
    47   set<student>::reverse_iterator begin = s.rbegin(),end = s.rend(),i;
    48   
    49   for(i=begin;i!=end;++i)
    50   {
    51     if((*i).grade >= grade1 && (*i).grade <= grade2)
    52     {
    53       cout<<i->name<<" "<<i->ID<<endl;
    54       flag = 0;
    55     }
    56   }
    57   
    58   if(flag)
    59     cout<<"NONE"<<endl;
    60 }
  • 相关阅读:
    Java核心技术第四章----对象与类重难点总结
    Java核心技术第三章----Java的基本程序设计结构重难点总结
    IDEA Invalid bound statement (not found)
    安利一个免费下载VIP文档神器
    灵魂拷问--你是什么垃圾?垃圾分类找人工智障!!!让你再也不拍大妈的灵魂拷问
    JavaWeb无框架,借助反射采用精巧设计模式实现放微信PC聊天页面
    JavaWeb购物车
    来自大专生的些许感悟
    2021 第二轮省队集训 Day5
    2021 第二轮省队集训 Day2
  • 原文地址:https://www.cnblogs.com/cdp1591652208/p/10227778.html
Copyright © 2020-2023  润新知