boys vs girls

给出n个同学的信息,输出女生中最高分数获得者的信息,和男生中最低分数获得者的信息,并输出成绩的差值。如果不存在女生或者男生则输出Absent,且差值为NA。

输入例子: 

Joe M Math990112 89 
Mike M CS991301 100 
Mary F EE990830 95

输出例子: 
Mary EE990830 
Joe Math990112 
6

struct person
{
	char name[15];
	char id[15];
	int score;
}temp,F,M;   //M为男生最低,F为女生最高
void init()
{
	F.score = -1; //初始化女生最高分数
	M.score = 100;  //初始化 男生最低分数
}

int main()
{
	init();
	int n;
	cin >> n;
	char ch;
	for (int i = 0; i < n; i++)
	{
		cin >> temp.name >> ch >> temp.id >> temp.score;
		
		if (ch == 'M' && temp.score < M.score)
		{
			M = temp;    //分数低于当前,则更新
		}
		else if (ch == 'F' && temp.score > F.score)
		{
			F = temp;      //高于则更新
		}
	}
	if (F.score == -1)  cout << "Absent" << endl;     //没女生
	else
		cout << F.name << F.id << endl;

	if (M.score == 101) cout << "Absent" << endl;   //没男生
	else
		cout << M.name << M.id << endl;

	if (F.score == -1 || M.score == 101) cout << "NA" << endl;  //没男生或没女生
	else
		cout << F.score - M.score << endl;

	return 0;
}

  

 

posted @ 2018-07-11 15:15  道微真理  阅读(354)  评论(0)    收藏  举报