An array A contains N (n>0) integers, and each integer loop is shifted to the right by the M (m>=0) position, and the data from a (a0a1 ...) is removed by the use of a different array. AN-1) transform to (an-m ... AN-1 A0 A1 ... AN-M-1) (the last m-number loop moves to the first m-position). If you need to consider the number of times a program moves data, how do you design a moving method?
input Format: Each input contains a test case, line 1th input n (1<=n<=100), M (m>=0), and line 2nd enter n integers, separated by a space.
output format: the sequence of integers after the output loop is shifted to the right of the M-bit in a row, separated by a space, with no extra spaces at the end of the sequence.
Input Sample:
6 21 2 3 4 5 6
Sample output:
5 6 1 2 3 4
1#include"stdio.h"2 #defineSize 1003 4 //move the array to the right one5 voidMove_array (intArr[],intlength)6 {7 inti,temp;8temp = arr[length-1];9 for(i =0; I < length-1; ++i)Ten { Onearr[length-1-I.] = arr[length-2-i]; A } -arr[0] =temp; - } the - intMainintargcChar Const*argv[]) - { - intA[size], length, times; + while(SCANF ("%d%d", &length, ×)! =EOF) - { + inti; A for(i =0; i < length; ++i) at { -scanf"%d", &a[i]); - } - for(i =0; I < (times% length); ++i) - { - Move_array (A, length); in } - for(i =0; i < length; ++i) to { + if(i = =0) -printf"%d", A[i]); the Else *printf"%d", A[i]); $ }Panax Notoginseng } - return 0; the}
1008. Loop right shift of array elements (20)