fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int N = 100 ;
  4. int a[N] ;
  5. int main() {
  6. int n ;
  7. cin>>n ;
  8. int frq[101] = {} ;
  9. for(int i = 0 ; i < n ; i++) /// O(n)
  10. {
  11. cin >> a[i];
  12. frq[a[i]]++ ;
  13. }
  14. for(int i = 0 ; i < n ; i++)
  15. {
  16. if(frq[a[i]] > 1)
  17. {
  18. cout<<a[i]<<' ' ;
  19. frq[a[i]] = 0 ;
  20. }
  21. }
  22. return 0;
  23. }
Success #stdin #stdout 0.01s 5288KB
stdin
10
1 1 2 2 3 3 4 4 5 6
stdout
1 2 3 4