思路:利用STL函数
#include<bits/stdc++.h>
using namespace std;
const int MAXSIZE = 10;
int main()
{
int n;
int a[MAXSIZE];
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
if (prev_permutation(a, a + n))//prev_permutation函数可以制造前一个排列,如果已经为第一个,则返回false
for (int i = 0; i < n; i++)
cout << a[i] << " ";
else cout << "ERROR";
return 0;
}