fork(1) download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. int main() {
  7. vector<int> arr = {1, 2, 3, 3, 3, 2, 3, 42, 1, 1}, tmp;
  8. for( int x : arr ){
  9. if(
  10. count_if(
  11. arr.begin(), arr.end(),
  12. [&x](int y){return x==y;}
  13. ) <= 2
  14. ) tmp.push_back(x) ;
  15. }
  16. arr = tmp;
  17. for( int x : arr ) {
  18. cout << x << endl;
  19. }
  20. cout << arr.size();
  21.  
  22.  
  23. // your code goes here
  24. return 0;
  25. }
Success #stdin #stdout 0s 3276KB
stdin
Standard input is empty
stdout
2
2
42
3