现在的位置: 首页 > 综合 > 正文

1036. Boys vs Girls

2014年09月05日 ⁄ 综合 ⁄ 共 1109字 ⁄ 字号 评论关闭

题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1036

仅仅求最大值与最小值,输入时进行比较久可以了,并且进行记录。没必要使用排序~~~

// 分类排序
// 

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <map>
#include <string>

using namespace std;

struct Stu
{
	char name[20];
	char id[20];
	char gender;
	int  grade;
};

vector<Stu> boy, girl;


bool cmpGirl(Stu a, Stu b)
{
	return a.grade>b.grade;
}

bool cmpBoy(Stu a, Stu b)
{
	return a.grade<b.grade;
}


int main()
	{
	#ifdef ONLINE_JUDGE
	#else 
		freopen("E:\\in.txt", "r", stdin);
	#endif 

	int n;
	scanf("%d", &n);
	Stu t;
	while(n-->0)
	{
		scanf("%s %c %s %d", &t.name, &t.gender, &t.id, &t.grade);
		//printf("%s %c %s %d\n", t.name, t.gender, t.id, t.grade);
		if(t.gender == 'F')
		{
			girl.push_back(t);
		}
		else
		{
			boy.push_back(t);
		}
	}

	sort(girl.begin(), girl.end(), cmpGirl);
	sort(boy.begin(), boy.end(), cmpBoy);
	bool flag = true;
	if(girl.size() == 0)
	{
		printf("Absent\n");
		flag = false;
	}
	else
	{
		printf("%s %s\n", girl[0].name, girl[0].id);
	}

	if(boy.size() == 0)
	{
		printf("Absent\n");
		flag = false;
	}
	else
	{
		printf("%s %s\n", boy[0].name, boy[0].id);
	}
	if(flag == false)
	{
		printf("NA\n");
	}
	else
	{
		printf("%d\n", girl[0].grade-boy[0].grade);
	}
	return 0;
}

抱歉!评论已关闭.