题目链接
https://www.patest.cn/contests/gplt/L2-019
思路
将已关注的人 用 MAP存起来
然后将点赞的用户中 没有关注的 用 VECTOR 存下来 并且求出 SUM
再遍历那个 VECTOR 用另一个VECTOR 存下 点赞数 大于平均数 的人
最后 排序 输出
AC代码
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <limits>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <string, int> psi;
const double PI = 3.14159265358979323846264338327;
const double E = exp(1);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
const int MOD = 1e9 + 7;
int main()
{
map <string, int> m;
int n;
scanf("%d", &n);
string s;
for (int i = 0; i < n; i++)
{
cin >> s;
m[s] = 1;
}
scanf("%d", &n);
double sum = 0.0;
int num;
vector <psi> v;
vector <string> ans;
for (int i = 0; i < n; i++)
{
cin >> s;
scanf("%d", &num);
sum += num;
if (m[s] == 0)
v.push_back(psi(s, num));
}
sum = sum * 1.0 / n;
vector <psi>::iterator it;
for (it = v.begin(); it != v.end(); it++)
{
if ((*it).second > sum)
ans.push_back((*it).first);
}
if (ans.size())
{
sort(ans.begin(), ans.end());
vector <string>::iterator iter;
for (iter = ans.begin(); iter != ans.end(); iter++)
cout << (*iter) << endl;
}
else
printf("Bing Mei You");
}