L2-019 悄悄关注

#include 
#include 
#include 
using namespace std;
//10 GAO3 Magi Zha1 Sen1 Quan FaMK LSum Eins FatM LLao
//8
//Magi 50
//Pota 30
//LLao 3
//Ammy 48
//Dave 15
//GAO3 31
//Zoro 1
//Cath 60
set name, ans;
typedef pair PII;
set arr;
int get_ave() {
	int sum = 0;
	for (auto x : arr) {
		sum += x.first;
	}
	return sum / arr.size();
}
int main() {
	int n;
	string s;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s;
		name.insert(s);
	}
	cin >> n;
	for (int i = 0, a; i < n; i++) {
		cin >> s >> a;
		arr.insert(PII(a, s));
	}
	int ave = get_ave();
	set::iterator it = arr.begin();
	while (it != arr.end()) {
		if (it->first > ave) break;
		it++;
	}
	while (it != arr.end()) {
		//set中的成员函数count底层是用红黑树实现的,所以查找起来会很快
		if (!name.count(it->second)) ans.insert(it->second);
		it++;
	}
	if (ans.empty()) cout << "Bing Mei You" << endl;
	for (auto x : ans) {
		cout << x << endl;
	}
	return 0;
}

你可能感兴趣的:(算法题,算法,c++,数据结构)