#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
//输入N个数,右移M位
int n,m;
int a[101];
int b[101];
int c[101];
int i,j = 0;
scanf("%d %d",&n,&m);
for(i = 0; i < n;i++)
{
scanf("%d",&a[i]);
}
//右移M位
//n个数,下标最多n-1
//6个数 0 - 5
//右移2位 (5+2)%2 = 1 下标移动到1
for(i = 0; i < n; i++){
b[j++] = (i + m)%n;
}
//b[]记录这a[]移动后的下标
//b[0] = 2 i = 0这个数要去到i = 2这个位置
for(i = 0; i < n; i++){
c[b[i]] = a[i];
}
for(i = 0;i < n;i++)
printf("%d",c[i]);
return 0;
}```
1008 数组元素循环右移问题
最新推荐文章于 2024-06-13 23:07:13 发布