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

     

  • 相关阅读:
    2024得物校招面试真题汇总及其解答(二)
    第四章 面向对象方法
    Debian 搭建 WireGuard 服务端
    蚂蚁核心架构师内部Java并发编程进阶笔记,白嫖简直太香了!
    cache知识点复习
    资本频频下注,为什么是江小白?
    Z410 2023款无人机,专为零基础开发者打造的入门级开源无人机
    Hudi学习二:Hudi基本概念
    TiUP 简介
    【Java 简洁初始化类】匿名内部类和实例初始化块
  • 原文地址:https://blog.csdn.net/weixin_53199925/article/details/125563181