PAT 1036 Boys vs Girls

#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>

using namespace std;

class Stu {
    public:
        char name[12];
        char id[12];
        int grade;
        char gender;
};

bool my_cmp(const Stu* a, const Stu* b) {
    return a->grade < b->grade;
}

void print (vector<Stu*> &stu) {
    int len = stu.size();
    for (int i=0; i<len; i++) {
        printf("%s %d\n", stu[i]->name, stu[i]->grade);
    }
}

int main() {
    vector<Stu*> male;
    vector<Stu*> female;
    int n = 0;
    scanf("%d", &n);

    for (int i=0; i<n; i++) {
        Stu* p = new Stu();
        scanf("%s %c %s %d", p->name, &(p->gender), p->id, &(p->grade));

        if (p->gender == ‘M‘) {
            male.push_back(p);
        } else {
            female.push_back(p);
        }
    }
    sort(male.begin(), male.end(), my_cmp);
    sort(female.begin(), female.end(), my_cmp);

    Stu* best = NULL;
    Stu* worst= NULL;

    if (female.empty()) {
        printf("Absent\n");
    } else {
        best = female[female.size() - 1];
        printf("%s %s\n", best->name, best->id);
    }
    if (male.empty()) {
        printf("Absent\n");
    } else {
        worst = male[0];
        printf("%s %s\n", worst->name, worst->id);
    }
    if (worst == NULL || best == NULL) {
        printf("NA\n");
    } else {
        printf("%d", best->grade - worst->grade);
    }
    return 0;
}

我感觉自己已经成脑残了,竟然忘了传my_cmp

时间: 2024-10-18 02:57:35

PAT 1036 Boys vs Girls的相关文章

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[简单]

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

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

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)-找最大最小,大水题

题意:给出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

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, f