오답노트
[순열] BOJ 10973 이전 순열 본문
https://www.acmicpc.net/problem/10973
- 문제 파악
주어진 순열의 사전순으로 이전 순열을 출력, 출력할 수 없을 때는 -1을 출력한다.
https://dhjkl123.tistory.com/46
- 정답
#include "bits/stdc++.h"
using namespace std;
int arr[10001];
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> arr[i];
}
if(prev_permutation(arr, arr+n))
{
for (int i = 0; i < n; i++)
{
cout << arr[i] << " ";
}
}
else
{
cout << -1;
}
}
'C,C++ > 코딩테스트' 카테고리의 다른 글
[순열] BOJ 10971 외판원 순회 2 (0) | 2022.05.08 |
---|---|
[순열] BOJ 10819 차이를 최대로 (0) | 2022.05.08 |
[순열] BOJ 10972 다음 순열 - 오답노트 (0) | 2022.05.07 |
[재귀] BOJ 2529 부등호 (0) | 2022.05.07 |
[재귀] BOJ 14889 스타트와 링크 - 오답노트 (0) | 2022.05.04 |