Код:
#include
int* rearrange(int *A, int Asize) {
int * result = new int[Asize];
int p = 0;
for (int i = 0; i < Asize; i += 2) {
result[p] = A[i];
++p;
}
for (int i = 1; i < Asize; i += 2) {
result[p] = A[i];
++p;
}
return result;
}
void print_arr(const int *A, int Asise) {
for (int i = 0; i < Asise; ++i) {
std::cout << A[i] << " ";</em>
}
}
int* change_it_k_times(int * const A, int Asize, int K) {
int * result = A;
for (auto i = 0; i < K; ++i) {
result = rearrange(result, Asize);
print_arr(result, Asize);
}
return result;
}
template
void get_sequence(T* A, int N) {
for (auto i = 0; i < N; ++i) {
std::cin >> A[i];
}
}
int main () {
int N, K;
std::cin >> N;
auto A = new int[N];
get_sequence(A, N);
std::cin >> K;
auto R = change_it_k_times(A, N, K);
delete[] A;
delete[] R;
return 0;
}