PAT1036 Boys vs Girls

Sample Input 1:

3
Joe M Math990112 89
Mike M CS991301 100
Mary F EE990830 95
Sample Output 1:
Mary EE990830
Joe Math990112
6
Sample Input 2:
1
Jean M AA980920 60
Sample Output 2:
Absent
Jean AA980920
NA

 

 

 

 

 

 

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
using namespace std;

struct STUDENT
{
    string name;
    char gender;
    string id;
    int grade;
};

int main()
{
    vector<STUDENT> VMale;
    vector<STUDENT> VFaMale;
    int N;
    cin>>N;
    while(N--)
    {
        STUDENT stu;
        cin>>stu.name>>stu.gender>>stu.id>>stu.grade;
        if (stu.gender == 'M')
        {
            VMale.push_back(stu);
        }
        else
        {
            VFaMale.push_back(stu);
        }
    }
    STUDENT highestFemale;
    int highest = 0;
    if (VFaMale.size() > 0)
    {

        vector<STUDENT>::iterator iterFemale = VFaMale.begin();
        highestFemale = *iterFemale;
        highest = (*iterFemale).grade;
        iterFemale++;
        while (iterFemale != VFaMale.end())
        {
            if ((*iterFemale).grade > highest)
            {
                highestFemale = *iterFemale;
                highest = highestFemale.grade;
            }
            iterFemale++;
        }
        cout<<highestFemale.name<<" "<<highestFemale.id<<endl;
    }
    else
    {
        cout<<"Absent"<<endl;
    }

    STUDENT lowmale;
    int lowest = 0;
    if (VMale.size() > 0)
    {

        vector<STUDENT>::iterator iterFemale = VMale.begin();
        lowmale = *iterFemale;
        lowest = (*iterFemale).grade;
        iterFemale++;
        while (iterFemale != VMale.end())
        {
            if ((*iterFemale).grade < lowest)
            {
                lowmale = *iterFemale;
                lowest = lowmale.grade;
            }
            iterFemale++;
        }
        cout<<lowmale.name<<" "<<lowmale.id<<endl;
    }
    else
    {
        cout<<"Absent"<<endl;
    }

    if (VMale.size() == 0 || VFaMale.size() == 0)
    {
        cout<<"NA";
    }
    else
    {
        cout<<highest - lowest;
    }

    return 0;
}
 

你可能感兴趣的:(pat)