-
Notifications
You must be signed in to change notification settings - Fork 0
/
f.cpp
67 lines (57 loc) · 1.18 KB
/
f.cpp
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define inf =1e18;
#define fr(n) for(ll i = 0 ; i < n ; i++)
int main()
{
ll t;
cin>>t;
while(t--)
{
ll n;
cin>>n;
ll mx=0;
ll a[n+4]={0};
//
fr(n)cin>>a[i];
map <ll ,ll >mp;
vector<ll > v;
// to have size of count array
int max = *max_element(a, a+n);
// auxiliary(count) array to
// store count. Initialize
// count array as 0. Size
// of count array will be
// equal to (max + 1).
int t = max + 1;
int count[t];
for (int i = 0; i < t; i++)
count[i] = 0;
// Store count of each element
// of input array
for (int i = 0; i < n; i++)
count[a[i]]++;
// mode is the index with maximum count
int mode = 0;
int k = count[0];
for (int i = 1; i < t; i++)
{
if (count[i] > k)
{
k = count[i];
}
}
for (int i = 1; i < t; i++)
{
if (count[i] == k)
{
v.push_back(i);
}
}
for(ll i=v.size()-1;i>=0;i)
cout<<v[i]<<" ";
cout<<endl;
}
return 0;
}