fork download
  1. #include <iostream>
  2. #include <set>
  3. #include <vector>
  4. #include <utility>
  5.  
  6.  
  7. using namespace std;
  8.  
  9.  
  10. int main() {
  11. std::set<int64_t> instance_indices(
  12. {-10, 0, 1, 2, 3, 10, 44, 11, 12, 15, 16, 17, 20, 21, 22}
  13. );
  14.  
  15. std::vector<std::pair<int64_t, int64_t>> continious_intervals;
  16.  
  17. int64_t pair_start = *instance_indices.begin();
  18. int64_t prev_value = pair_start;
  19. auto it = instance_indices.begin(); it++;
  20. for (; it != instance_indices.end(); it++) {
  21. if (prev_value + 1 != *it) {
  22. continious_intervals.push_back({pair_start, prev_value});
  23. pair_start = *it;
  24. }
  25. prev_value = *it;
  26. }
  27. continious_intervals.push_back({pair_start, prev_value});
  28.  
  29.  
  30. for(auto it = continious_intervals.begin(); it != continious_intervals.end(); it++) {
  31. cout << "(" << it->first << " , " << it->second << ")" << endl;
  32. }
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
(-10 , -10)
(0 , 3)
(10 , 12)
(15 , 17)
(20 , 22)
(44 , 44)