Advertisement
StoneHaos

Untitled

Jun 30th, 2020
1,190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. using namespace std;
  6.  
  7. int main(void) {
  8.     srand(time(NULL));
  9.  
  10.     int n;
  11.     cin >> n;
  12.     int *arr = new int[n];
  13.     for (int i = 0; i < n; ++ i) {
  14.         arr[i] = rand() % 100 - 50;
  15.         cout << arr[i] << " ";
  16.     }
  17.     int *nw = new int[n];
  18.     int b = 0;
  19.     for (int i = 0; i < n; ++ i) {
  20.         if ((i + 1) % 2 == 0 && arr[i] > 0)
  21.             nw[b ++] = i;
  22.     }
  23.     int c = b;
  24.     for (int i = 0; i < n; ++ i) {
  25.         bool flag = true;
  26.         for (int j = 0; j < b; ++ j)
  27.             if (i == nw[j])
  28.                 flag = false;
  29.         if (flag)
  30.             nw[c ++] = i;
  31.     }
  32.     for (int i = 0; i < n; ++ i)
  33.         nw[i] = arr[nw[i]];
  34.  
  35.     cout << "\n";
  36.     for (int i = 0; i < n; ++ i)
  37.         cout << nw[i] << " ";
  38.     cout << "\n";
  39.  
  40.     delete [] nw;
  41.     delete [] arr;
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement