Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- #include <time.h>
- using namespace std;
- int main(void) {
- srand(time(NULL));
- int n;
- cin >> n;
- int *arr = new int[n];
- for (int i = 0; i < n; ++ i) {
- arr[i] = rand() % 100 - 50;
- cout << arr[i] << " ";
- }
- int *nw = new int[n];
- int b = 0;
- for (int i = 0; i < n; ++ i) {
- if ((i + 1) % 2 == 0 && arr[i] > 0)
- nw[b ++] = i;
- }
- int c = b;
- for (int i = 0; i < n; ++ i) {
- bool flag = true;
- for (int j = 0; j < b; ++ j)
- if (i == nw[j])
- flag = false;
- if (flag)
- nw[c ++] = i;
- }
- for (int i = 0; i < n; ++ i)
- nw[i] = arr[nw[i]];
- cout << "\n";
- for (int i = 0; i < n; ++ i)
- cout << nw[i] << " ";
- cout << "\n";
- delete [] nw;
- delete [] arr;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement