Advertisement
myloyo

6.5.15

Dec 4th, 2022 (edited)
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int n, k;
  8.     cin >> n >> k;
  9.     int *a = new int[2*n];
  10.     for (int i = 0; i < n; i++) {
  11.         cin >> a[i];
  12.     }
  13.     for (int i = 0; i < n; i++) {
  14.         if ((a[i]*a[i+1]) < 0) {
  15.             for (int j = n; j > i; j--) {
  16.                 a[j] = a[j - 1];
  17.             }
  18.             a[i + 1] = k;
  19.             n++;
  20.             i += 2;
  21.         }
  22.     }
  23.     for (int i = 0; i < n; i++) {
  24.         cout << a[i] << " ";
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement