-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFavourite_Singer.cpp
60 lines (51 loc) · 1.46 KB
/
Favourite_Singer.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
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
long num, temp;
vector<long> singerList;
cin >> num; // Reading no of songs in playlist
for (long i = 1; i <= num; i++) // ith integer denotes singer of ith song.
{
cin >> temp;
singerList.push_back(temp);
}
std::sort(singerList.begin(), singerList.end());
// find frequencuy of each element in vecter
long i = 0;
vector<long> countFreq;
while (i < singerList.size())
{
int c = 1;
i++;
while (i < singerList.size())
{
if (singerList[i] == singerList[i - 1])
c++;
else
{
break;
}
i++;
}
countFreq.push_back(c);
}
// find max in countFreq and its frequency.
std::sort(countFreq.begin(), countFreq.end());
long j = 0;
int count = 0, last = countFreq.back();
while (j < countFreq.size())
{
if (countFreq[j] == last)
count++;
j++;
}
cout << count;
}