Alive Fossils

题目大意

给定那场camps的名单,输出每场都在的人。

解题思路

用map存每个人出现的次数,最后遍历map如果出现的次数与camps场数相同就输出。

因为map已经自动实现了排序,所以不需要自己排序。

参考代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'

bool multi=0;


void solve(){
int n;
cin>>n;
map<string,int> mp;
for(int i=0;i<n;i++){
int t;
cin>>t;
while(t--){
string s;
cin>>s;
mp[s]++;
}
}
int res=0;
for(auto it:mp){
if(it.second==n){
res++;
}
}
cout<<res<<'\n';
for(auto it:mp){
if(it.second==n) cout<<it.first<<'\n';
}
}

signed main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int T=1;
if(multi) cin>>T;
while(T--){
solve();
}

return 0;
}