1008 数组元素循环右移问题 (20 分)
#include <iostream> #include <algorithm> #include <list> using namespace std; int main(){ int n, m; cin >> n >> m; int *p = new int[n]; for (int i = 0; i < n; i++) cin >> p[i]; m = m % n; reverse(p, p + n - m); // 算法精髓 reverse(p + n - m, p + n); reverse(p, p + n); for (int i = 0; i < n; i++){ if (i == 0) cout << p[i]; else cout << ' ' << p[i]; } delete[] p; cout << endl; return 0; }