fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. vector<int> a(10), b;
  10.  
  11. srand(time(0));
  12.  
  13. for (auto &i : a) {
  14. i = (rand() % 100) - 50;
  15. cout << i << endl;
  16. if (i >= 0) {
  17. b.push_back(i);
  18. }
  19. }
  20.  
  21. sort(b.begin(), b.end());
  22. cout << endl << endl;
  23.  
  24. auto it = b.begin();
  25. for (auto &i : a) {
  26. if (i >= 0) {
  27. i = *it++;
  28. }
  29. cout << i << endl;
  30. }
  31. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
36
-42
1
-11
-47
-4
-38
28
-39
-31


1
-42
28
-11
-47
-4
-38
36
-39
-31