-
Notifications
You must be signed in to change notification settings - Fork 0
/
Find the Frequency.cpp
58 lines (48 loc) · 989 Bytes
/
Find the Frequency.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
//{ Driver Code Starts
// Initial Template for C++
#include <bits/stdc++.h>
using namespace std;
// } Driver Code Ends
// User function Template for C++
/*Function to find frequency of x
* x : element whose frequency is to be found
* v : input vector
*/
int findFrequency(vector<int> v, int x)
{
int counter = 0;
for (int i = 0; i < v.size(); i++)
{
if (v[i] == x)
{
counter++;
}
}
return counter;
}
//{ Driver Code Starts.
int main()
{
int testcase;
cin >> testcase;
while (testcase--)
{
int N;
cin >> N;
// Declaring vector
vector<int> v;
// Taking vector element input
for (int i = 0; i < N; i++)
{
int k;
cin >> k;
v.push_back(k);
}
// element whose frequency to be find
int x;
cin >> x;
cout << findFrequency(v, x) << endl;
}
return 0;
}
// } Driver Code Ends