3108. 循环右移数组元素

Naive函数数组普通指针

时间限制:2000 ms

内存限制:256 MiB

题面

nn (1n101 \leq n \leq 10) 个元素组成的数组的各个元素向右移动 mm (m<nm < n) 个位置,右边的 mm 个元素移到开头位置。

//********** Specification of input **********
void input(int* p, int n);
/* PreCondition:
p points to an array with n integers
PostCondition:
enter and store n integers into an array pointed by p
*/
//********** Specification of rotate **********
void rotate(int* p, int n, int m);
/* PreCondition:
p points to an array with n integers, m is also an integer
PostCondition:
rotate m elements of an array
*/
//********** Specification of output **********
void output(int* p, int n);
/* PreCondition:
p points to an array with n integers
PostCondition:
print each element of an array pointed by p in one line, with one blank between elements.
*/

只需按要求写出函数定义,并使用给定的测试程序测试你所定义函数的正确性。

不要改动测试程序。

测试正确后,将测试程序和函数定义一起提交。

/***************************************************************/
/*                                                             */
/*  DON'T MODIFY main function ANYWAY!                         */
/*                                                             */
/***************************************************************/
#include <stdio.h>
#define N 10
//********** Specification of input **********
void input(int* p, int n)
/* PreCondition:
p points to an array with n integers
PostCondition:
enter and store n integers into an array pointed by p
*/
{ //TODO: your function definition
}
//********** Specification of rotate **********
void rotate(int* p, int n, int m)
/* PreCondition:
p points to an array with n integers, m is also an integer
PostCondition:
rotate m elements of an array
*/
{ //TODO: your function definition
}
//********** Specification of output **********
void output(int* p, int n)
/* PreCondition:
p points to an array with n integers
PostCondition:
print each element of an array pointed by p in one line,
with one blank between elements.
*/
{ //TODO: your function definition
}
/***************************************************************/
int main()
{
	int a[N],n,m;
	scanf("%d%d",&n,&m);
	//***** functions input, rotate, output are called here ******
	input(a,n);
	rotate(a,n,m);
	output(a,n);
	//************************************************************
	return 0;
}