fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4.  
  5. int main() {
  6. std::vector<int> unsorted = {10, 20, 5, 15, 25};
  7.  
  8. auto lb = std::lower_bound(unsorted.begin(), unsorted.end(), 15);
  9. auto ub = std::upper_bound(unsorted.begin(), unsorted.end(), 15);
  10.  
  11. std::cout << "Lower Bound: " << (lb - unsorted.begin()) << std::endl;
  12. std::cout << "Upper Bound: " << (ub - unsorted.begin()) << std::endl;
  13.  
  14. return 0;
  15. }
  16.  
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Lower Bound: 3
Upper Bound: 4