티스토리 뷰

백준/실버

[백준 10972번] 다음 순열 (C++)

게임개발기원 2025. 4. 3. 18:33

문제링크 : 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을 출력해준다.

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/08   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함