PAT 1036. Boys vs Girls

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<cmath>
#include<iomanip>
#include<algorithm>
using namespace std;

struct Student
{
	char chName[15];
	char chId[15];
	int iScore;
};

bool lessCmp(Student stu1, Student stu2)
{
	return stu1.iScore < stu2.iScore;
}

bool greaterCmp(Student stu1, Student stu2)
{
	return stu1.iScore > stu2.iScore;
}

int main()
{
	vector<Student> vBoys,vGirls;
	int N,i;
	char cGender;
	Student stuTmp;
	cin>>N;
	for(i=0; i<N; i++)
	{
		cin>>stuTmp.chName>>cGender>>stuTmp.chId>>stuTmp.iScore;
		if(cGender == 'M')
			vBoys.push_back(stuTmp);
		else
			vGirls.push_back(stuTmp);
	}
	if(vGirls.size() == 0)
		cout<<"Absent"<<endl;
	else
	{
		sort(vGirls.begin(),vGirls.end(),greaterCmp);
		cout<<vGirls[0].chName<<" "<<vGirls[0].chId<<endl;
	}
	if(vBoys.size() == 0)
		cout<<"Absent"<<endl;
	else
	{
		sort(vBoys.begin(),vBoys.end(),lessCmp);
		cout<<vBoys[0].chName<<" "<<vBoys[0].chId<<endl;
	}
	if(vGirls.size() == 0 || vBoys.size() == 0)
		cout<<"NA"<<endl;
	else
		cout<<vGirls[0].iScore-vBoys[0].iScore<<endl;
	return 0;
}

  

posted @ 2012-12-15 09:34  Frank@609  Views(228)  Comments(0Edit  收藏  举报