PAT1036. Boys vs Girls (25)

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct Student{
	string name;
	string gender;
	string id;
	int grade;
	int idd;
};
int n;
bool cmp(Student a,Student b){
	return a.grade<b.grade;
}
vector<Student> studentSet;
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		Student s;
		cin>>s.name>>s.gender;
		cin>>s.id>>s.grade;
		s.idd=i;
		studentSet.push_back(s);
	}
	sort(studentSet.begin(),studentSet.end(),cmp);
	int p=-1,q=-1;
	for(int i=0;i<n;i++){
		if(studentSet[i].gender[0]=='M'){
			if(p==-1){p=i;}
		}
		if(studentSet[i].gender[0]=='F'){
			q=i;
		}
	}
	int flag=-1;
	if(q==-1){
		cout<<"Absent"<<endl;
		flag=1;
	}else{
		cout<<studentSet[q].name<<" "<<studentSet[q].id<<endl;
	}
	if(p==-1){
		cout<<"Absent"<<endl;
		flag=1;
	}else{
		cout<<studentSet[p].name<<" "<<studentSet[p].id<<endl;
	}
	if(flag==-1){
		cout<<(studentSet[q].grade-studentSet[p].grade)<<endl;
	}else{
		cout<<"NA"<<endl;
	}
    return 0;
}

 

posted @ 2016-03-27 16:16  Yellowman  阅读(377)  评论(0编辑  收藏  举报
TVRBMExqRXlPQzR5TXpjdU1UVTEK\n