SHARE
TWEET

Untitled

a guest Jan 22nd, 2020 73 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, firstPositive = -1;
  11.     while(cin >> x){
  12.         v.push_back(x);
  13.         if(x >= 0 && firstPositive == -1){
  14.             firstPositive = v.size() - 1;
  15.         }
  16.     }
  17.     for(int i = 0; i < v.size(); i++){
  18.         if(v[i] < 0 && i > firstPositive && firstPositive != -1) {
  19.             swap(v[i], v[firstPositive]);
  20.             for(int j = firstPositive; j < v.size(); j++){
  21.                 if(v[j] >= 0){
  22.                     firstPositive = j;
  23.                     break;
  24.                 }
  25.             }
  26.         }
  27.     }
  28.     int pos = -1;
  29.     for(vector<int>::iterator it = v.begin(); it != v.end(); it++){
  30.         if(*it >= 0){
  31.             reverse(v.begin(), it);
  32.             break;
  33.         }
  34.     }
  35.     for(int i = 0; i < v.size(); i++){
  36.         cout << v[i] << " ";
  37.     }
  38.     return 0;
  39. }
  40. /*
  41. -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
  42. */
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