๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm ๐Ÿง‘๐Ÿป‍๐Ÿ’ป/๋ฐฑ์ค€(BOJ)

[๋ฐฑ์ค€,c++] 10974๋ฒˆ - ๋ชจ๋“  ์ˆœ์—ด

by dkswnkk 2021. 10. 25.
 

10974๋ฒˆ: ๋ชจ๋“  ์ˆœ์—ด

N์ด ์ฃผ์–ด์กŒ์„ ๋•Œ, 1๋ถ€ํ„ฐ N๊นŒ์ง€์˜ ์ˆ˜๋กœ ์ด๋ฃจ์–ด์ง„ ์ˆœ์—ด์„ ์‚ฌ์ „์ˆœ์œผ๋กœ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

www.acmicpc.net

 

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int N; cin >> N;
    bool flag = true;
    vector<int>v;
    for (int i = 1; i <= N; i++) {
        v.push_back(i);
    }

    while (flag) {
        for (int i = 0; i < N; i++) {
            cout << v[i] << ' ';
        }
        cout << "\n";
     flag=next_permutation(v.begin(), v.end());    //๋‹ค์Œ ์ˆœ์—ด์ด ์—†์œผ๋ฉด false ๋ฐ˜ํ™˜.
    }
}

๋Œ“๊ธ€