Pat 1036 boys vs girls

Source: Internet
Author: User
#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;}

I feel like I have lost my brains. I forgot to upload my_cmp.

Pat 1036 boys vs girls

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.