1036 Boys vs Girls (25 分)

 

#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

const int maxn = 1010;
struct person {
	string name;
	string num;
	int scr;
}m[maxn],w[maxn];

bool cmp2(struct person& a, struct person& b) {
	return a.scr < b.scr;
}
bool cmp1(struct person& a, struct person& b) {
	return a.scr > b.scr;
}
int main()
{
	int n;
	cin >> n;
	int cnt_m = 0, cnt_w = 0;
	for (int i = 0; i < n; i++) {
		string str1, str2, str3;
		int tmp;
		cin >> str1 >> str2 >> str3 >> tmp;
		if (str2 == "M") {
			m[cnt_m].name = str1;
			m[cnt_m].num = str3;
			m[cnt_m++].scr = tmp;
		}
		if (str2 == "F") {
			w[cnt_w].name = str1;
			w[cnt_w].num = str3;
			w[cnt_w++].scr = tmp;
		}
	}
	if (cnt_w != 0) {
		sort(w, w + cnt_w, cmp1);
		cout << w[0].name << " " << w[0].num << endl;
	}
	else {
		cout << "Absent" << endl;
	}
	if (cnt_m != 0) {
		sort(m, m + cnt_m, cmp2);
		cout << m[0].name << " " << m[0].num << endl;
	}
	else {
		cout << "Absent" << endl;
	}
	if (cnt_m != 0 && cnt_w != 0) {
		cout << abs(m[0].scr - w[0].scr);
	}
	else {
		cout << "NA" << endl;
	}
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值