문제 :
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;
}
'algorithm > ACMICPC' 카테고리의 다른 글
테트로미노 - 14500 (0) | 2019.11.19 |
---|---|
모든 순열 - 10974 (0) | 2019.11.19 |
다음 순열 - 10972 (0) | 2019.11.19 |
차이를 최대로 - 10819 (0) | 2019.11.19 |
1, 2, 3 더하기 - 9095 (0) | 2019.11.19 |
댓글