#include <iostream>
#include <vector>
using namespace std;
const int ARRAY_SIZE = 7;
int check_shift_position(int array_size, int m);
void shift_array(int array[ARRAY_SIZE], int m);
void print_array (int array[ARRAY_SIZE]);
int main() {
int array[ARRAY_SIZE];
for(int i =0; i < ARRAY_SIZE; i++) {
cin >> array[i];
}
int m = 0;
cin >> m;
m = check_shift_position(ARRAY_SIZE,m);
cout << "Initial array = ";
print_array(array);
shift_array(array, m);
return 0;
}
int check_shift_position(int array_size, int m)
{
if (array_size < m) {
return m%array_size;
}
return m;
}
void shift_array(int array[ARRAY_SIZE], int m) {
// Init shifted array
int shifted_array[ARRAY_SIZE];
// Shift elements for [m + 1..n] to start;
for (int i = m, k = 0; i < ARRAY_SIZE ; i++,k++) {
shifted_array[k] = array[i];
}
// Shift elements for [0..m] to the end;
for (int i = 0, k = ARRAY_SIZE - m; i < m ; i++,k++) {
shifted_array[k]= array[i];
}
cout << "Shifted array = ";
print_array(shifted_array);
}
void print_array (int array[ARRAY_SIZE]) {
for (int i = 0; i < ARRAY_SIZE ; i++) {
cout << array[i] << " ";
}
cout << endl;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IEFSUkFZX1NJWkUgPSA3OwoKCmludCBjaGVja19zaGlmdF9wb3NpdGlvbihpbnQgYXJyYXlfc2l6ZSwgaW50IG0pOwp2b2lkIHNoaWZ0X2FycmF5KGludCBhcnJheVtBUlJBWV9TSVpFXSwgaW50IG0pOwp2b2lkIHByaW50X2FycmF5IChpbnQgYXJyYXlbQVJSQVlfU0laRV0pOwoKaW50IG1haW4oKSB7CgkKCWludCBhcnJheVtBUlJBWV9TSVpFXTsKCQoJZm9yKGludCBpID0wOyBpIDwgQVJSQVlfU0laRTsgaSsrKSB7CgkJY2luID4+IGFycmF5W2ldOwoJfQoJCglpbnQgbSAgPSAwOwoJY2luID4+IG07CgkKCW0gPSBjaGVja19zaGlm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