An arrayAA is stored inNN>0>0) Integer to move each integer loop to the right without allowing the use of a different arrayMM\ge 0≥0) a position that willAThe data in a is determined by (A_0 a_1 \cdots A_{n-1}A?0??A?1???A?N?1?? ) Transformation to (A_{N-M} \cdots a_{n-1} a_0 a_1 \cdots a_{n-m-1}A?N?M???A?N?1??A?0??A?1???a?Nm? 1?? ) (Last mm number of loops moved to the front < Span class= "Katex-mathml" >mm locations). 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, and line 1th entersNN1\le N \le 1001≤n≤ 100) and mm (\ge 0 ≥0); line 2nd enter n< span class= "Strut" > n integers, separated by a space.
Output format:
In a row, the output loop moves right through the integer sequence of M-bits, 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>#include<math.h>intMain () {intN =0, M =0, i =0; intarr[ $]; scanf ("%d%d", &n, &M); //Boundary judgment if(N <=0|| N > -|| M <0){ return 0; } //get the initial list for(; i < N; i++) {scanf ("%d",&Arr[i]); } //if the right shift exceeds the length, the loop movesm = m%N; //output the remaining length after right shift for(i = n-m; i < N; i++) {printf ("%d", Arr[i]); } //then output to the left after the right shift. for(i =0; I < n-m-1; i++) {printf ("%d", Arr[i]); } printf ("%d", Arr[i]); return 0;}
Self-test-3 array elements loop right shift problem