티스토리 뷰
문제링크 : https://www.acmicpc.net/problem/10972
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N;
int arr[10001];
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> N;
for(int i=0; i<N; i++) cin >> arr[i];
if(next_permutation(arr, arr+N))
{
for(int i=0; i<N; i++) cout << arr[i] << " ";
}
else cout << -1;
return 0;
}
next_permutation 함수를 통해 현재 배열에 대한 다음 조합이 있는 지 간단하게 체크가 가능하다.
if문을 통해 있다면 배열 값을, 없다면 -1을 출력해준다.
'백준 > 실버' 카테고리의 다른 글
[백준 1850번] 최대공약수 (C++) (0) | 2025.04.10 |
---|---|
[백준 4134번] 다음 소수 (C++) (0) | 2025.04.09 |
[백준 13909번] 창문 닫기 (C++) (0) | 2025.03.30 |
[백준 13241]번 최소공배수 (C++) (0) | 2025.03.30 |
[백준 24313번] 알고리즘 수업 - 점근적 표기 1 (C++) (0) | 2025.03.27 |