B1008 array elements rotate right questions (20 minutes)

topic

  • Note that the value of m may be greater than n
#include <iostream>
#include <math.h>
using namespace std;
int main(){
	int n,m;
	cin >> n >> m;
	int array[n];
	for (int i=0;i<n;i++){
		scanf("%d",&array[i]);
	}
	m %=n ;
	for (int i=n-m;i<n;i++){
		printf("%d",array[i]);
		printf(" ");
	}
	for (int i=0;i<n-m;i++){
		if(i!=0)printf(" ");
		printf("%d",array[i]);
	}
} 
Published 91 original articles · won praise 9 · views 10000 +

Guess you like

Origin blog.csdn.net/WeDon_t/article/details/105012820