fork download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. int main() {
  5. int v[] = {1,1,1,1,1,4,5};
  6. auto p = std::equal_range( std::begin(v), std::end(v), 1 );
  7. if( p.first != p.second ) {
  8. auto it = p.second - 1;
  9. std::cout << std::distance( std::begin(v), it ) << std::endl;
  10. }
  11. }
Success #stdin #stdout 0s 4492KB
stdin
Standard input is empty
stdout
4