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

     

  • 相关阅读:
    OrcaTerm AI
    Java并发编程的艺术总结(1)
    dubbo3+zookeeper/nacos+dubbo-admin
    第一个接受素数定理的人
    安卓12手机不能安装问题记录
    Element UI怎么安装呢?
    ChatGPT用10秒画完一张UML流程图,而我用了。。。
    JVM基础04_对象
    Unity基础课程之物理引擎6-关于物理材质的使用和理解
    近红外II区荧光量子点细胞膜/两亲性不对称双离子苝酰亚胺染料标记细胞膜的制备
  • 原文地址:https://blog.csdn.net/weixin_53199925/article/details/125563181