fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. vector<int>v={1,2,4,4,5};
  5.  
  6. void ub(int num){
  7. cout<<upper_bound(v.begin(),v.end(),num)-v.begin()<<endl;
  8. }
  9.  
  10. int main() {
  11. ub(3); //if number is not present
  12. ub(4); //if number is present
  13. ub(7); //if number if bigger than max
  14. return 0;
  15. }
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
2
4
5