c-moodle/homework/11975.c

39 lines
687 B
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <stdio.h>
int a[114514];
int k, n;
void move(int* arr, int len, int n) {
int b[191910];
// 初始化数组b
for (int i = 0; i < len; i++)
b[i] = 0;
int i;
for (i = 0; i < len; i++) {
// 对于数组a中第i个元素移动n位后应该移动到(i+n)%len的位置
b[(i + n) % len] = arr[i];
}
for (i = 0; i < len; i++) {
printf("%d ", b[i]);
}
}
int main() {
// 读入数组a
while (scanf("%d", &a[k])) {
if (a[k] == 9999)
break;
k++;
}
// 读入需要右移的位数n
scanf("%d", &n);
// 调用函数move进行右移
move(a, k, n);
return 0;
}