• 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

    题目大意

    找出女生中最高得分的那位A,与男生中得分最低的那位B

    依次输出 :

    A.name A.score , 不存在 输出 Absent

    B.name B.score , 不存在 输出 Absent

    abs(A.score,B.score)  A或B有一个不存在,输出 NA


    思路

    超级简单的一道题...


    C/C++ 

    1. #include
    2. using namespace std;
    3. int main()
    4. {
    5. int N,score,boy=2022,girl=-2021;
    6. string name,id,boyName,boyId,girlName,girlId,sex;
    7. cin >> N;
    8. while (N--){
    9. cin >> name >> sex >> id >> score;
    10. if(sex=="M" && score
    11. boy = score;
    12. boyName = name;
    13. boyId = id;
    14. }
    15. if(sex=="F" && score>girl){
    16. girl = score;
    17. girlName = name;
    18. girlId = id;
    19. }
    20. }
    21. if(girl!=-2021) cout << girlName << " " << girlId << endl;
    22. else cout << "Absent" << endl;
    23. if(boy!=2022) cout << boyName << " " << boyId << endl;
    24. else cout << "Absent" << endl;
    25. if(girl!=-2021 && boy!=2022) cout << abs(boy-girl) << endl;
    26. else cout << "NA" << endl;
    27. return 0;
    28. }

  • 相关阅读:
    GIS前端编程-Leaflet插件扩展
    solidity使用create2预测合约地址|create2用法|智能合约create2
    容器编排学习(十)控制器介绍与使用
    Elasticsearch 8.4.1 配置自签名证书和启用Https
    云导DNS和知识科普以及课堂笔记
    MyBatis 源码分析之 SqlSession 创建
    关于HTTP模块访问之后响应网页
    王爽《汇编语言》检测点11.2详细解析
    【蓝桥每日一题]-动态规划 (保姆级教程 篇12)#照相排列
    重装系统后新建文本文档打不开怎么办
  • 原文地址:https://blog.csdn.net/daybreak_alonely/article/details/127758667