码迷,mamicode.com
首页 > 其他好文 > 详细

PAT 1036 Boys vs Girls

时间:2014-10-31 21:54:22      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   color   os   ar   for   sp   div   

#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

PAT 1036 Boys vs Girls

标签:style   blog   io   color   os   ar   for   sp   div   

原文地址:http://www.cnblogs.com/lailailai/p/4066008.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!