inhuman_Arif

Ques 3

Oct 7th, 2021
762
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. typedef long long ll;
  5.  
  6. int main()
  7. {
  8.     #ifndef ONLINE_JUDGE
  9.         freopen("input.txt", "r", stdin);
  10.         freopen("output.txt", "w", stdout);
  11.     #endif
  12.  
  13.     int n;
  14.     cin >> n;
  15.     int mx = -1;
  16.     int arr[n];
  17.    
  18.     for(int i = 0; i < n; i++){
  19.         cin >> arr[i];
  20.         mx = max(arr[i], mx);
  21.     }
  22.  
  23.     int freq[mx] = {0};
  24.  
  25.  
  26.     for(int j = 0; j < n; j++){
  27.         freq[arr[j]]++;
  28.     }
  29.  
  30.     int mergearr[n+2];
  31.     int i = 0;
  32.  
  33.     for(int j = 0; j <= mx; j++)
  34.     {
  35.         if(freq[j] >= 1)
  36.             mergearr[i++] = j;
  37.         if(freq[j] > 1)  
  38.             printf("%d %d\n",j,freq[j]);
  39.     }
  40.     for(int j = 0; j < i; j++)
  41.         cout << mergearr[j] << ' ';
  42.     cout << endl;
  43.    
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment