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;
}
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值