L2-019 Quiet Attention (STL)

topic link

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

ideas

For the name of the watch list, we use one map<string,bool>to mark whether it appears, and then the following users and like information can pair<string,name>be stored, and finally traverse the liked users to find out the users who are not following the user and the number of likes is greater than the average, Finally, sort the output, if not, outputBing Mei You

code

#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;
}

Guess you like

Origin blog.csdn.net/m0_46201544/article/details/123976307