Self-test-3 array elements loop right shift problem

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.