A1036 Boys vs Girls (25 分| 查找元素,附详细注释,逻辑分析)

写在前面
  • 思路分析
    • string型female和male保存要求的学生信息
    • int型fscore和mscore保存男生最低分和女生最高分
      • 初始化fscore-1, mscore为最大值101
      • 根据性别、分数大小迭代更新:
        • female和male
        • fscore和mscore
  • 题目简单,不再赘述
    • 15分钟a题目
测试用例
  • input:
    3
    Joe M Math990112 89
    Mike M CS991301 100
    Mary F EE990830 95
    
    output:
    Mary EE990830
    Joe Math990112
    6
    
    input:
    1
    Jean M AA980920 60
    
    output:
    Absent
    Jean AA980920
    NA
    
ac代码
  • #include <iostream>
    using namespace std;
    
    int main()
    {
        int n;
        scanf("%d", &n);
        string female, male;
        int fscore = -1, mscore = 101;
    
        for(int i=0; i<n; i++)
        {
            string name, sex, num;
            int score;
            cin >> name >> sex >> num;
            scanf("%d", &score);
    
            if(sex == "F")
            {
                if(fscore < score)
                {
                    fscore = score;
                    female = name + " " + num;
                }
            }
            else if (mscore > score)
            {
                mscore = score;
                male = name + " " + num;
            }
        }
        if(fscore != -1)
            cout << female << endl;
        else
            printf("Absent\n");
        if(mscore != 101)
            cout << male << endl;
        else
            printf("Absent\n");
        if(mscore != 101 && fscore != -1)
            printf("%d", fscore-mscore);
        else
            printf("NA\n");
    
        return 0;
    }
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xsimah

创作不易,感谢客官的打赏

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值