fork download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.  
  8. string texts[4] = { "C", "C++", "Java", "Python" };
  9. int size = sizeof(texts) / sizeof(texts[0]);
  10. sort(texts, texts + size);
  11.  
  12. string target = "C++";
  13. if (binary_search(texts, texts + 4, target)) {
  14. string* idx = lower_bound(texts, texts + 4, target);
  15. cout << (idx - texts) << endl;
  16. } else {
  17. cout << "Not found." << endl;
  18. }
  19.  
  20. return 0;
  21.  
  22. }
  23.  
  24.  
Success #stdin #stdout 0.01s 5516KB
stdin
Standard input is empty
stdout
1