An array A contains N (n>0) integers, and each integer loop is shifted to the right by M (m>=0), and the data from a (a~0~ a~1~ ...) is not allowed to use a different array. a~n-1~) transform to (a~n-m~ ... a~n-1~ a~0~ a~1~ ... a~n-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
#include <stdio.h>Main () {intI,j,k,x,n; inta[ -]; scanf ("%d%d", &n,&k);//N is the number of arrays, and K is the number of moves for(i=0; i<n;i++) scanf ("%d",&A[i]); while(k) {x=a[i-1]; for(j=i-1;j>0; j--) {A[j]=a[j-1]; } a[0]=x; K--; } printf ("%d", a[0]); for(i=1; i<n;i++) {printf ("%d", A[i]); }}
1008 array element Loop right shift problem (20)