fork(5) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.  
  9. std::vector<int> tt { 15, 25 };
  10. std::vector<int> cc { 10, 20, 30 } ;
  11.  
  12. auto lower = std::lower_bound(cc.begin(), cc.end(), tt.front(), [](int a, int b){ return a < b; });
  13. auto upper = std::lower_bound(cc.rbegin(), cc.rend(), tt.back(), [](int a, int b){ return a > b; });
  14.  
  15. size_t beforeCount = lower - cc.begin();
  16. size_t afterCount = upper - cc.rbegin();
  17.  
  18. std::cout << beforeCount << std::endl;
  19. std::cout << afterCount << std::endl;
  20.  
  21. std::cout << cc[beforeCount] << std::endl;
  22. std::cout << cc[afterCount] << std::endl;
  23.  
  24. return 0;
  25. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
1
1
20
20