题目:
输入样例:
6 2
1 2 3 4 5 6
输出样例:
5 6 1 2 3 4
分析:格式错误。
注意测试点:
1 0
1
不右移数据,直接输出。
#include<bits/stdc++.h>
using namespace std;
int main()
{
int N = 0, M = 0;
cin >> N >> M;
vector<int> v(N + 1);
for (int i = 0; i < N; ++i) cin >> v[i];
M = M % N;
for (int i = N - M; i < N; ++i) {
i != N - M ? cout << ' ' << v[i] : cout << v[i];
}
if (M != 0)cout << ' ';
for (int i = 0; i < N - M; ++i)
i != 0 ? cout << ' ' << v[i] : cout << v[i];
return 0;
}
右移数据后输出。
#include<bits/stdc++.h>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<int> v(N+1);
for (int i = 0; i < N; i++)cin >> v[i];
M %= N;
if (M != 0) {
reverse(begin(v), begin(v) + N);
reverse(begin(v), begin(v) + M);
reverse(begin(v) + M, begin(v) + N);
}
for (int i = 0; i < N; i++)
i!=N-1 ? cout << v[i] << " " : cout << v[i];
return 0;
}