Published 2021. 1. 21. 23:40
 

10974번: 모든 순열

N이 주어졌을 때, 1부터 N까지의 수로 이루어진 순열을 사전순으로 출력하는 프로그램을 작성하시오.

www.acmicpc.net

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i=0; i<n; i++) {
        a[i] = i+1;
    }
    do {
        for (int i=0; i<n; i++) {
            cout << a[i] << ' ';
        }
        cout << '\n';
    } while (next_permutation(a.begin(), a.end()));
    return 0;
}

 

'Problem set' 카테고리의 다른 글

[백준] 10971 외판원 순회 2  (0) 2021.01.21
[백준] 10819 차이를 최대로  (0) 2021.01.21
[백준] 10973 이전 순열  (0) 2021.01.21
[백준] 10972 다음 순열  (0) 2021.01.21
[백준] 15666 N과 M (12)  (0) 2021.01.21
복사했습니다!