fork download
  1. //{ Driver Code Starts
  2. // Initial Template for C++
  3. #include <bits/stdc++.h>
  4. using namespace std;
  5.  
  6.  
  7. // } Driver Code Ends
  8.  
  9. // User function Template for C++
  10.  
  11. /*Function to find frequency of x
  12.  * x : element whose frequency is to be found
  13.  * arr : input vector
  14.  */
  15. class Solution {
  16. public:
  17. int findFrequency(vector<int> arr, int x) {
  18. // Your code here
  19. int n=arr.size();
  20. map<int,int>mp;
  21. for(int num:arr){
  22. mp[num]++;
  23. }
  24. return mp[x];
  25. }
  26. };
  27.  
  28.  
  29.  
  30. //{ Driver Code Starts.
  31. int main() {
  32. int t;
  33. cin >> t;
  34. cin.ignore();
  35. while (t--) {
  36. string line;
  37. getline(cin, line);
  38. stringstream ss(line);
  39. vector<int> arr;
  40. int num;
  41. while (ss >> num) {
  42. arr.push_back(num);
  43. }
  44. int x;
  45. cin >> x;
  46. cin.ignore();
  47. Solution ob;
  48. cout << ob.findFrequency(arr, x) << endl;
  49. }
  50.  
  51. return 0;
  52. }
  53. // } Driver Code Ends
Success #stdin #stdout 0.01s 5300KB
stdin
Standard input is empty
stdout
Standard output is empty