01调函数实现全排列

2020-03-14  本文已影响0人  HelloSam
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
    int n;
    cin >> n;//求1-n的全排列

    vector<int> vi;
    for (int i=1;i<=n;i++)
    {
        vi.push_back(i);
    }

    do 
    {
        for (int i=0;i<n;i++)
        {
            cout << vi[i] << " ";
        }
        cout << endl;
    } while (next_permutation(vi.begin(),vi.end()));

/*
    int a[3] = { 1,2,3 };
    do 
    {
        cout << a[0] << a[1] << a[2] <<endl;
    } while (next_permutation(a,a+3));
*/
    return 0;
}
输入3
输入5
上一篇下一篇

猜你喜欢

热点阅读