algorithm/ACMICPC
이전 순열 - 10973
에어컨조아
2019. 11. 19. 23:49
문제 :
https://www.acmicpc.net/problem/10973
10973번: 이전 순열
첫째 줄에 입력으로 주어진 순열의 이전에 오는 순열을 출력한다. 만약, 사전순으로 가장 처음에 오는 순열인 경우에는 -1을 출력한다.
www.acmicpc.net
소스 :
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int n;
cin >> n;
int num[10000] = { 0 };
for (int i = 0; i < n; i++)
{
cin >> num[i];
}
bool check = prev_permutation(num, &num[n]);
if (check)
{
for (int i = 0; i < n; i++)
{
cout << num[i];
if (i < n - 1)
cout << " ";
}
}
else
{
cout << -1 << endl;
}
return 0;
}