1036 Boys vs Girls (25分)

1. 题目

2. 思路

vector<node> m, vector<node> f 分别存放女性和男性,后排序比较

3. 注意点

4. 代码

#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<string>

using namespace std;

struct stu{
    string name;
    string id;
    int grade;
    stu(char name[100], char id[100], int grade){
        this->name = name;
        this->id = id;
        this->grade = grade;
    }
};

bool cmpM(stu s1, stu s2){
    return s1.grade < s2.grade;
}

bool cmpF(stu s1, stu s2){
    return s1.grade > s2.grade;
}

int n;
int main(){
    char name[50], sex[2], id[50];
    int grade;
    vector<stu> m;
    vector<stu> f;
    scanf("%d", &n);
    for(int i=0;i<n;i++){
        scanf("%s %s %s %d", name, sex, id, &grade);
        if(string(sex) == "M"){
            m.push_back(stu(name, id, grade));
        }else{
            f.push_back(stu(name, id, grade));
        }
    }
    sort(f.begin(), f.end(), cmpF);
    sort(m.begin(), m.end(), cmpM);
    if(f.size() == 0){
        printf("Absent\n");
        if(m.size() == 0){
            printf("Absent\n");
        }else{
            printf("%s %s\n", m[0].name.c_str(), m[0].id.c_str());
        }
        printf("NA\n");
    }else{
        printf("%s %s\n", f[0].name.c_str(), f[0].id.c_str());
        if(m.size() == 0){
            printf("Absent\n");
            printf("NA\n");
        }else{
            printf("%s %s\n", m[0].name.c_str(), m[0].id.c_str());
            printf("%d\n", f[0].grade - m[0].grade);
        }
    }

}

原文地址:https://www.cnblogs.com/d-i-p/p/12416596.html

时间: 2024-10-07 05:50:46

1036 Boys vs Girls (25分)的相关文章

PAT 甲级 1036 Boys vs Girls (25 分)(简单题)

1036 Boys vs Girls (25 分) 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 contai

PAT 1036 Boys vs Girls (25 分)

1036 Boys vs Girls (25 分) 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 contai

1036. Boys vs Girls (25)

1036. Boys vs Girls (25) 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 contain

PAT 1036. Boys vs Girls (25)

1036. Boys vs Girls (25) 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 contain

PAT甲题题解-1036. Boys vs Girls (25)-找最大最小,大水题

题意:给出n个人的姓名.性别.ID.分数,让你找出其中哪个妹纸分数最高.哪个汉子分数最低.以及他们的差如果没有妹纸或者汉子,则对应输出Absent,差用NA代替. 就是for一遍找最大最小值,水题 #include <iostream> #include <cstdio> #include <algorithm> #include <string.h> #include <cmath> #include <vector> #defin

PAT (Advanced Level) 1036. Boys vs Girls (25)

简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> #include<map> #include<queue> #include<vector> using namespace std; const int maxn=100000; struct X { string nam

pat1036. Boys vs Girls (25)

1036. Boys vs Girls (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue 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 Spec

1036 Boys vs Girls (25 分)

1036 Boys vs Girls (25 分) 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 contai

PAT 1036 Boys vs Girls[简单]

1036 Boys vs Girls (25 分) 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 contai