fork(1) download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. int SPECIAL = 100500;
  5.  
  6. struct less
  7. {
  8. bool operator() (int a, int b)
  9. {
  10. if (a == SPECIAL || b == SPECIAL)
  11. return false;
  12. return a < b;
  13. }
  14. };
  15.  
  16. int main()
  17. {
  18. int a[]= {7, 3, 4, 1, SPECIAL, 4, 9};
  19. int b[]= {7, 3, 4, 1, 5, 4, 9};
  20.  
  21. std::sort(std::begin(a), std::end(a), less());
  22. std::sort(std::begin(b), std::end(b), less());
  23.  
  24. for (int aa : a) {
  25. std::cout << aa << " ";
  26. }
  27. std::cout << std::endl;
  28.  
  29. for (int bb : b) {
  30. std::cout << bb << " ";
  31. }
  32. std::cout << std::endl;
  33.  
  34. std::cout << "max = " << *std::max_element(std::begin(a), std::end(a), less()) << std::endl;
  35. std::cout << "min = " << *std::min_element(std::begin(a), std::end(a), less())<< std::endl;
  36.  
  37. std::cout << "max = " << *std::max_element(std::begin(b), std::end(b), less()) << std::endl;
  38. std::cout << "min = " << *std::min_element(std::begin(b), std::end(b), less())<< std::endl;
  39.  
  40. return 0;
  41. }
  42.  
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
1 3 4 7 100500 4 9 
1 3 4 4 5 7 9 
max = 9
min = 1
max = 9
min = 1