PTA悄悄关注

一、题目描述

 

 二、解题思路

  定义一个map,set,vector,vector负责存答案,map负责统计人和分数的映射,最后遍历答案串的时候,如果他没有在set里面出现过,并且他的map映射的分数大于平均分,那么就是答案,直接输出就可以。

三、代码实现

 1 #include "bits/stdc++.h"
 2 using namespace std;
 3 set <string> q;
 4 map <string,double> sc;
 5 vector <string> ans;
 6 int main()
 7 {
 8     int n;
 9     cin >> n;
10     while(n--){
11         string a;
12         cin >> a;
13         q.insert(a);
14     }
15     int m;
16     double sum = 0;
17     cin >> m;
18     n = m;
19     while(m--){
20         string a;
21         double score;
22         cin >> a;
23         cin >> score;
24         sum += score;
25         ans.push_back(a);
26         sc[a] = score;
27     }
28     double ave = sum / n;
29     int d = 0;
30     sort(ans.begin(),ans.end());
31     for(auto &u : ans){
32         if(!q.count(u) && sc[u] > ave){
33             cout << u << endl;
34             d++;
35         }
36     }
37     if(!d)
38         cout << "Bing Mei You" << endl;
39     return 0;
40 }
posted @ 2022-03-19 15:30  scannerkk  阅读(71)  评论(0)    收藏  举报