利用set的自动排序功能

#include<iostream>
#include<map>
#include<set>
using namespace std;

struct like{
    string name;
    int num;
}wb[1000000];

int main(){
    int n,m;
    map<string,int> mp;
    cin>>n;
    set<string> st;
    for(int i=0;i<n;i++){
        string a;
        cin>>a;
        mp[a]=1;
    }
    cin>>m;
    double s=0;
    for(int i=0;i<m;i++){
        cin >> wb[i].name >>wb[i].num;
        s+=wb[i].num;
    }
    s/=m;
    int flag=0;
    for(int i=0;i<m;i++){
        if(wb[i].num>s&&mp.count(wb[i].name)==false){
            flag=1;
            st.insert(wb[i].name);
        }
    }
    if(flag==0)
        cout<<"Bing Mei You";
    else{
        for(set<string>::iterator it=st.begin();it!=st.end();it++){
            cout<<*it<<endl;
        }
    }
}

题目详情 - 7-3 悄悄关注 (25 分) (pintia.cn)

posted @ 2021-12-31 17:46  兮何其  阅读(163)  评论(0)    收藏  举报