• 1036 Boys vs Girls


    This time you are asked to tell the difference between the lowest grade of all the male students and the highest grade of all the female students.

    Input Specification:

    Each input file contains one test case. Each case contains a positive integer N, followed by N lines of student information. Each line contains a student's namegenderID and grade, separated by a space, where name and ID are strings of no more than 10 characters with no space, gender is either F (female) or M (male), and grade is an integer between 0 and 100. It is guaranteed that all the grades are distinct.

    Output Specification:

    For each test case, output in 3 lines. The first line gives the name and ID of the female student with the highest grade, and the second line gives that of the male student with the lowest grade. The third line gives the difference gradeF​−gradeM​. If one such kind of student is missing, output Absent in the corresponding line, and output NA in the third line instead.

    Sample Input 1:

    1. 3
    2. Joe M Math990112 89
    3. Mike M CS991301 100
    4. Mary F EE990830 95

    Sample Output 1:

    1. Mary EE990830
    2. Joe Math990112
    3. 6

    Sample Input 2:

    1. 1
    2. Jean M AA980920 60

    Sample Output 2:

    1. Absent
    2. Jean AA980920
    3. NA
    1. #include <iostream>
    2. #include <string>
    3. using namespace std;
    4. int main() {
    5. int n, fmax = -1, mmin = 101, score;
    6. string fName, fId, mName, mId, name, gender, id;
    7. cin >> n;
    8. for (int i = 0; i < n; i++) {
    9. cin >> name >> gender >> id >> score ;
    10. if (score > fmax && gender == "F") {
    11. fName = name;
    12. fId = id;
    13. fmax = score;
    14. }
    15. if (score < mmin && gender == "M") {
    16. mName = name;
    17. mId = id;
    18. mmin = score;
    19. }
    20. }
    21. bool flag = 0;
    22. if (fmax == -1) {
    23. cout << "Absent" << endl;
    24. flag = 1;
    25. } else {
    26. cout << fName << ' ' << fId << endl;
    27. }
    28. if (mmin == 101) {
    29. cout << "Absent" << endl;
    30. flag = 1;
    31. } else {
    32. cout << mName << ' ' << mId << endl;
    33. }
    34. if (flag) {
    35. cout << "NA";
    36. } else {
    37. cout << fmax - mmin;
    38. }
    39. return 0;
    40. }

     

  • 相关阅读:
    笔试强训(三十五)
    gsteamer日志输出实例
    2023.9.1 简单认识 JVM
    QT读取DLL加载算法
    零基础学前端(五)重点讲解 JavaScript
    【面试常见问题】深拷贝与浅拷贝
    mysql 按照时间戳字段每5年统计一次记录数
    接地继电器DD-1/60
    【WSN定位】基于chan算法实现无源定位附matlab代码
    云原生 | kubernetes - Ingress
  • 原文地址:https://blog.csdn.net/weixin_53199925/article/details/125563181