Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- void FillArray(int a[], int n){
- for (int i = 0; i < n; i++)
- cin >> a[i];
- }
- void PrintArray(int a[], int n){
- cout << endl;
- for (int i = 0; i < n; i++)
- cout << a[i] << " ";
- }
- void Add(int *a, int pos, int x, int n){
- for (int i = n; i > pos; i--){
- a[i] = a[i - 1];
- }
- a[pos] = x;
- }
- int main()
- {
- int n, x;
- cin >> n >> x;
- int *a = new int [2*n];
- FillArray(a, n);
- for (int i = 0; i < n - 1; i++){
- if ((a[i] < 0 && a[i+1] > 0) || (a[i] > 0 && a[i+1] < 0)){
- Add(a, i + 1, x, n);
- n++;
- }
- }
- PrintArray(a, n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement