#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main() {
int n, m,i,j;
int *nPointer;
scanf("%d%d", &n, &m);
m = m%n; //如果移动次数过多,相当于只移动了m%n这么多次
nPointer = (int *)malloc(4 * (n + 1));
memset(nPointer, 0, sizeof(4 * (n + 1)));
//获取
for (i = 0; i < n; i++) {
scanf("%d", (nPointer + i));
}
//移动
for (j = 0; j < m; j++) {
for (i = n; i >= 0; i--) {
*(nPointer + i + 1) = *(nPointer + i);
if (i == 0) {
*(nPointer) = *(nPointer + n);
}
}
}
//打印
for (i = 0; i < n ; i++) {
printf("%d", *(nPointer + i));
if (i != n - 1) {
printf(" ");
}
}
//system("pause");
return 0;
}
PAT-乙级 1008 数组元素循环右移问题(C语言)
最新推荐文章于 2022-03-18 22:39:09 发布