fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <unordered_map>
  4. #include <algorithm>
  5. using namespace std;
  6.  
  7.  
  8.  
  9. int main() {
  10. vector<int> v{12,8,8,6,4,3,3};
  11. std::vector<int> result;
  12. std::unordered_map<int, int> hashMap;
  13. bool update = false;
  14. for(auto cur : v) {
  15. hashMap[cur]++;
  16. }
  17. do {
  18.  
  19. update = false;
  20. for (auto cur : hashMap) {
  21. if (cur.second == 2) {
  22. hashMap[cur.first + 1]++;
  23. hashMap.erase(cur.first);
  24. update = true;
  25. }
  26. }
  27. } while(update);
  28. for (auto cur : hashMap) {
  29. result.push_back(cur.first);
  30. }
  31. std::sort(result.begin(), result.end(), std::greater<int>());
  32. v = result;
  33.  
  34. for (auto&x : result)std::cout << x << ".";
  35. return 0;
  36. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
12.9.6.5.