• PAT甲级--1083 List Grades 分数 25


    题目链接:题目详情 - 1083 List Grades (pintia.cn)

    题目:

    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:

    1. N
    2. name[1] ID[1] grade[1]
    3. name[2] ID[2] grade[2]
    4. ... ...
    5. name[N] ID[N] grade[N]
    6. 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:

    1. 4
    2. Tom CS000001 59
    3. Joe Math990112 89
    4. Mike CS991301 100
    5. Mary EE990830 95
    6. 60 100

    Sample Output 1:

    1. Mike CS991301
    2. Mary EE990830
    3. Joe Math990112

    Sample Input 2:

    1. 2
    2. Jean AA980920 60
    3. Ann CS01 80
    4. 90 95

    Sample Output 2:

    NONE

    代码:

    1. #include
    2. using namespace std;
    3. struct Stu {
    4. string name, ID;
    5. int grade;
    6. };
    7. int cmp(Stu a, Stu b) {
    8. return a.grade > b.grade;
    9. }
    10. int main()
    11. {
    12. int N, st, en, flag = 1;
    13. cin >> N;
    14. vector v(N);
    15. for (int i = 0; i < N; ++i) {
    16. cin >> v[i].name >> v[i].ID >> v[i].grade;
    17. }
    18. cin >> st >> en;
    19. sort(v.begin(), v.end(), cmp);
    20. for (int i = 0; i < N; ++i) {
    21. if (v[i].grade >= st && v[i].grade <= en) {
    22. cout << v[i].name << " " << v[i].ID << endl;
    23. flag = 0;
    24. }
    25. }
    26. if (flag)cout << "NONE";
    27. return 0;
    28. }

  • 相关阅读:
    [C语言基础]文件读取模式简析
    Redis分布式锁
    【JavaScript】JS语法入门到实战
    123. 买卖股票的最佳时机 III
    Programming Abstractions in C阅读笔记:p306-p307
    商业化广告--概念理解--DSP SSP RTB 是一个怎样的过程
    如何给git分支添加备注,更新远程分支
    resultmap
    linux如何查看各个文件夹大小
    深度学习基础之过拟合、欠拟合问题和正则化
  • 原文地址:https://blog.csdn.net/weixin_68051436/article/details/125901492