Dowemo

1008. Array elements loop right to right ( 20 ) time limit 400 ms.
Memory limit 65536 kb
Code length limit 8000 b
program Standard

A> ( n 0 ) integer is stored in an array a, where each integer loop is moved to the right ( m> = 0 ), and the data from ( a0a1. An-1 ) is converted to ( an-m. AN-1 ) a1. If you need to consider how many times the program moves data, how to design a move?

input format: each input contains a test case, line 1 to n ( 1 <= n <= 100 ), m> = 0 ); Line 2 enters n integers, separated by spaces separated by spaces.

output format: output loop on one line to the right of the m sequence, separated by spaces, and the end of the sequence can't have extra space.

input sample:

6 2


1 2 3 4 5 6






output sample:

5 6 1 2 3 4





My solution.

#include<iostream>


using namespace std;


int a[100];


int main()


{


 int N,M;


 scanf("%d%d",&N,&M);


 for(int i=0;i<N;++i)//在输入时就调整顺序


 scanf("%d",&a[(i+M)%N]);


 for(int i=0;i<N;++i)


 {


 if(i==0)


 printf("%d",a[i]);


 else 


 printf(" %d",a[i]);


 } 


 return 0;


 } 











Copyright © 2011 Dowemo All rights reserved.    Creative Commons   AboutUs