A1036. Boys vs Girls

 

 

 

 

基本思路#

  • 构造Person结构体,属性,姓名,性别,编号,分数
  • 初始化Girl与Boy属性,在遍历中记录Girl最高分和Boy最低分
  • 检查是否缺失男性或者女性,按照题目要求输出对应格式
复制代码
#include <bits/stdc++.h>

using namespace std;

struct Person{
    int score;
    string name, id, sex;
}Girl, Boy, temp;

void init(){
    Girl.score = 0;
    Girl.sex = 'F';
    Boy.score = 100;
    Boy.sex = 'M';
}

int main(int argc, char* argv[]) {
    init();
    int n, score;
    cin >> n;
    string name, id, sex;
    bool flag_M, flag_F;
    flag_M = flag_F = false;
    for(int i = 0; i < n; i++){    
        cin >> name >> sex >> id >> score;
        if(sex == "M"){
            flag_M = true;
            if(score < Boy.score){
                Boy.id = id;
                Boy.name = name;
                Boy.score = score;
            }    
        }else if(sex == "F"){
            flag_F = true;
            if(score > Girl.score){
                Girl.id = id;
                Girl.name = name;
                Girl.score = score;
            }    
        }        
    } 
    bool flag = false;
    // 不存在女生 
    if(flag_F == false){
        flag = true;
        cout << "Absent" << endl;
    }else{
        cout << Girl.name << ' ' << Girl.id << endl;        
    }
    // 不存在男生 
    if(flag_M == false){
        flag = true;
        cout << "Absent" << endl;
    }else{
        cout << Boy.name << ' ' << Boy.id << endl;
    }
    if(flag){
        cout << "NA" << endl;
    }else{
        cout << (Boy.score < Girl.score ? Girl.score - Boy.score : Boy.score - Girl.score) << endl;
    }
    return 0;
}
复制代码
posted @   BigBender  阅读(166)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
点击右上角即可分享
微信分享提示
主题色彩