A1036. Boys vs Girls

Posted yc-l

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;
}

以上是关于A1036. Boys vs Girls的主要内容,如果未能解决你的问题,请参考以下文章

PAT 甲级 1036 Boys vs Girls(20)

1036. Boys vs Girls (25)

1036 Boys vs Girls (25 分)

1036 Boys vs Girls (25分)

1036 Boys vs Girls

1036 Boys vs Girls