题目描述
Given an array, rotate the array to the right by k steps, where k is non-negative.
输入
第一行两个整数n,k表示数字的数量和移动的次数(n<=100,k<=1000)
第二行给出n个数
输出
输出k次移动后的数组
样例输入
7 3
1 2 3 4 5 6 7
样例输出
5 6 7 1 2 3 4
提示
Explanation:
rotate 1 steps to the right:[7,1,2,3,4,5,6]
rotate 2 steps to the right:[6,7,1,2,3,4,5]
rotate 3 steps to the right:[5,6,7,1,2,3,4]
#include<iostream>
using namespace std;
int main()
{
int n,k,i;
cin>>n>>k;
int a[n],b[n];
for(i=0;i<n;i++)
{
cin>>a[i];
int s=(i+k%n)%n;
b[s]=a[i];
}
for(i=0;i<n;i++)
cout<<b[i]<<" ";
return 0;
}