• 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. }

     

  • 相关阅读:
    Java开发注意事项和细节说明
    数仓开发之DWD层(三)
    快速构建基本的SpringCloud微服务
    C51--开发环境
    Worthington公司天冬氨酸氨基转移酶特异性说明
    【第6天】SQL快速入门-综合练习(SQL 小虚竹)
    第八章——常用数据排序算法之归并排序
    程序假死怎么办
    计算机网络笔记汇总链接
    视觉语言模型详解
  • 原文地址:https://blog.csdn.net/weixin_53199925/article/details/125563181