SHARE
TWEET

Untitled

a guest Jan 22nd, 2020 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     vector<int> v;
  10.     int x;
  11.     while(cin >> x){
  12.         v.push_back(x);
  13.     }
  14.     for(int i = 0; i < v.size(); i++){
  15.         if(v[i] < 0){
  16.             while(i > 0 && v[i - 1] >= 0) {
  17.                 swap(v[i], v[i - 1]);
  18.                 i--;
  19.             }
  20.         }
  21.     }
  22.     for(vector<int>::iterator it = v.begin(); it != v.end(); it++){
  23.         if(*it >= 0){
  24.             reverse(v.begin(), it);
  25.             break;
  26.         }
  27.     }
  28.     for(int i = 0; i < v.size(); i++){
  29.         cout << v[i] << " ";
  30.     }
  31.     return 0;
  32. }
  33. /*
  34. -8 7 9 2 -2 1 -1 9 -5 2 -8 1 8 1 -5 0 2 5 6 6 9 -6 -3 -4 0 7 2 6 0 7 -4 0 1 -5 -9 2 9 -3 -5 7 6 9 -8 -7 -4 1 -6 -4 5 -1
  35. */
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top