fork(4) download
  1. #include <algorithm>
  2. #include <vector>
  3. #include <iterator>
  4. #include <iostream>
  5.  
  6. int main()
  7. {
  8. std::vector<int> v { 1, 1, 2, 3, 3, 5, 5, 5 }; // must be sorted...
  9.  
  10. auto i = begin(v);
  11. while (i != end(v))
  12. {
  13. auto ub = upper_bound(begin(v), end(v), *i);
  14. std::cout << distance(i, ub) << std::endl;
  15. i = ub;
  16. }
  17. }
Success #stdin #stdout 0s 2984KB
stdin
Standard input is empty
stdout
2
1
2
3