fork download
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<vector>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. int main(int argc, char ** argv)
  9. {
  10. vector<double> v1(10);
  11. vector<double>::iterator i;
  12. vector<double>::const_iterator position;
  13. double key = 5.7;
  14.  
  15. double n=10.0;
  16. for(i=v1.begin(); i!=v1.end(); i++)
  17. {
  18. *i = n-=0.5;
  19. cout<<*i<<" ";
  20. }
  21. cout<<endl;
  22.  
  23. position = find( v1.begin(), v1.end(), key );
  24.  
  25. while(position == v1.end())
  26. {
  27. key-=0.1;
  28. cout<<"key: "<<key<<endl;
  29. position = find(v1.begin(), v1.end(), key);
  30. cout<<"index: "<<position - v1.begin()<<endl;
  31. if(key<5.0) break;
  32. }
  33. int index = position - v1.begin();
  34. cout<<"index: "<<index<<endl;
  35. return 0;
  36. }
  37.  
Success #stdin #stdout 0s 3232KB
stdin
Standard input is empty
stdout
9.5 9 8.5 8 7.5 7 6.5 6 5.5 5 
key: 5.6
index: 10
key: 5.5
index: 10
key: 5.4
index: 10
key: 5.3
index: 10
key: 5.2
index: 10
key: 5.1
index: 10
key: 5
index: 10
key: 4.9
index: 10
index: 10