#include <bits/stdc++.h>
#define N 100
using namespace std;
void Reverse(int R[], int l, int r)
{
int i, j;
int temp;
for (i = l, j = r; i < j; i++, j--)
{
temp = R[i];
R[i] = R[j];
R[j] = temp;
}
}
void RCR(int R[], int n, int P)
{
if (P <= 0 || P >= n)
{
cout << "ERROR" << endl;
exit(0);
}
else
{
Reverse(R, 0, P - 1);
Reverse(R, P, n - 1);
Reverse(R, 0, n - 1);
}
}
int main()
{
int i, n, P, R[N];
cin >> n >> P;
for (i = 0; i < n; i++)
{
cin >> R[i];
}
RCR(R, n, P);
for (i = 0; i < n; i++)
{
cout << R[i] << " ";
}
return 0;
}
原文:https://www.cnblogs.com/zhulu506/p/14939294.html