-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind_the_frequency.cpp
57 lines (52 loc) · 1.28 KB
/
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
/*Given a vector of N positive integers and an integer X. The task is to find the frequency of X in vector.
Input Format:
First line of input contains number of testcases T. For each testcase there will be three lines. First line of which contains N,
size of vector. Second line contains N positive integers seperated by space, and third line contains X, whose frequency is required.
Output Format:
For each testcase, print the frequency of X.
User Task:
Your task is to complete the function findFrequency() which should count the frequency of X and return it.
Constraints:
1 <= T <= 100
1 <= N <= 106
1 <= V[i] <= 1016
Example:
Input:
1
5
1 1 1 1 1
1
Output:
5
Explanation:
Testcase 1: Frequency of 1 is 5.
Link- https://practice.geeksforgeeks.org/problems/find-the-frequency/1 */
#include<bits/stdc++.h>
#define f(i,a,b) for(i=a;i<b;i++)
#define sp "\t"
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
main()
{
int tc=0;
cin>>tc;
int n,x,i;
vector<int> a;
while(tc>0)
{
tc--;
cin>>n;
a.resize(n);
f(i,0,n)
{
cin>>x;
a.push_back(x);
}
cin>>x;
}
cout<<count(a.begin(),a.end(),x);
//vector<int> vect{ 3, 2, 1, 3, 3, 5, 3 };
}