• PAT 1036 Boys and Girls


    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
    2. using namespace std;
    3. int main(){
    4. int n;
    5. cin >> n;
    6. string s,id,fname,mname;
    7. char c;
    8. int t,fm=-1,mm=0x3f3f3f3f;//fm表示女生最大值,mm表示男生最小值
    9. bool f=false,m=false;
    10. for(int i=0;i
    11. cin >> s >> c >> id >> t;
    12. if(c=='F'){
    13. f=true;
    14. if(fm
    15. fm=t;
    16. fname=s+' '+id;
    17. }
    18. }
    19. else{
    20. m=true;
    21. if(mm>t){
    22. mm=t;
    23. mname=s+' '+id;
    24. }
    25. }
    26. }
    27. f==true?cout << fname << endl:cout << "Absent" << endl;
    28. m==true?cout << mname << endl:cout << "Absent" << endl;
    29. if(!f || !m) printf("NA");
    30. else printf("%d\n",fm-mm);
    31. return 0;
    32. }

    好好学习,天天向上!

    我要考研

    2022.11.4

    1. /*
    2. 思路:找出女生里面的最高分,找到男生里的最低分,(找最值的时候需要加上性别进行限制),最后根据分数来判断
    3. 是否有找到最低分的男生,最高分的女生
    4. */
    5. #include
    6. using namespace std;
    7. int main(){
    8. int maxg=-1,ming=101,n;
    9. string maxname,maxid,minname,minid;
    10. scanf("%d",&n);
    11. string name,id;
    12. char c;
    13. int g;
    14. for(int i=0;i
    15. cin >> name >> c >> id >> g;
    16. if(g>maxg && c=='F'){//女生里的最高分
    17. maxg=g;
    18. maxid=id;
    19. maxname=name;
    20. }
    21. else if(g'M'){//男生里的最低分
    22. ming=g;
    23. minid=id;
    24. minname=name;
    25. }
    26. }
    27. bool sign=false;
    28. if(maxg==-1){
    29. printf("Absent\n");
    30. sign=true;
    31. }
    32. else cout << maxname << ' ' << maxid << endl;
    33. if(ming==101){
    34. printf("Absent\n");
    35. sign=true;
    36. }
    37. else cout << minname << ' ' << minid << endl;
    38. if(sign) printf("NA\n");
    39. else printf("%d\n",maxg-ming);
    40. return 0;
    41. }

  • 相关阅读:
    蓝桥杯练习题十 - 煤球数目(c++)
    Cilium系列-11-启用带宽管理器
    《吐血整理》高级系列教程-吃透Fiddler抓包教程(33)-Fiddler如何抓取WebSocket数据包
    Java8流Stream的创建和操作
    三、RestClient操作索引库与文档
    大数据库题目集——判断题
    linux-Too many open files排查及修复
    【精讲】vue框架watch监测、技能提升案例、天气预报案例、watch及computed区别
    Tkinter绘制股票K线图
    什么是C语言中的命名空间?
  • 原文地址:https://blog.csdn.net/weixin_50679551/article/details/126936959