fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. //#include <cstddef>
  5.  
  6. int main()
  7. {
  8. std::vector<size_t> m_index_list;
  9.  
  10. m_index_list.push_back(0);
  11. m_index_list.push_back(5);
  12. m_index_list.push_back(9);
  13. m_index_list.push_back(9);
  14.  
  15. for (size_t data_pos = 4; data_pos < 12; ++data_pos)
  16. {
  17. // your code goes here
  18. auto it = upper_bound(m_index_list.begin(), m_index_list.end(), data_pos);
  19.  
  20. //it != end(m_index_list)
  21.  
  22. size_t fragment_index = it - m_index_list.begin();
  23.  
  24. std::cout << "data_pos " << data_pos << ": fragment_index = " << fragment_index << std::endl;
  25. }
  26.  
  27. return 0;
  28. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
data_pos 4: fragment_index = 1
data_pos 5: fragment_index = 2
data_pos 6: fragment_index = 2
data_pos 7: fragment_index = 2
data_pos 8: fragment_index = 2
data_pos 9: fragment_index = 4
data_pos 10: fragment_index = 4
data_pos 11: fragment_index = 4