L2-019 悄悄关注(STL)

题目连接

https://pintia.cn/problem-sets/994805046380707840/problems/994805059731177472

思路

对于关注列表的名字,我们通过一个map<string,bool>进行标记是否出现,然后下面的用户和点赞信息可以通过pair<string,name>进行存储,最后遍历一遍点赞的用户,找出其中不在关注用户且点赞数量大于平均的人,最后排序输出即可,如果没有的话输出Bing Mei You

代码

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define endl "\n"
#define PII pair<int,int>
#define INF 0x3f3f3f3f

int n,m;

map<string,bool> vis;

int main()
{
    
    
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	string name;
	for(int i = 1;i <= n; ++i) {
    
    
		cin>>name;
		vis[name] = true;
	}
	cin>>n;
	int star,sum = 0;
	vector<pair<string,int>> Vec;
	for(int i = 1;i <= n; ++i) {
    
    
		cin>>name>>star;
		Vec.push_back({
    
    name,star});
		sum += star;
	}
	vector<string> ans;
	for(int i = 0;i < n; ++i) {
    
    
		if(Vec[i].second * n > sum && vis[Vec[i].first] == false) 
			ans.push_back(Vec[i].first);
	}
	if(ans.size() == 0) cout<<"Bing Mei You"<<endl;
	else {
    
    
		sort(ans.begin(),ans.end());
		for(auto it: ans)
			cout<<it<<endl;
	}
	
	return 0;
}

猜你喜欢

转载自blog.csdn.net/m0_46201544/article/details/123976307