全排列2

版权声明:个人做题总结专用~ https://blog.csdn.net/tb_youth/article/details/84311826

对next_permutation的使用

1683: 排列
Time Limit: 1 Sec Memory Limit: 128 MB
[Submit][Status][Web Board]
Description

给你一个数,输出所有的排列

Input

一个数n

Output

看样例

Sample Input

2

Sample Output

1 2
2 1

AC代码:

#include <stdio.h>
#include <algorithm>
using namespace std;
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int a[n];
        for(int i = 0; i < n; i++)
        {
            a[i] = i+1;
        }
        do
        {
            int i = 0;
            printf("%d",a[i]);
            for( i = 1; i < n; i++)
                printf(" %d",a[i]);
            printf("\n");
        }while(next_permutation(a,a+n));
    }
    return 0;
}

/*
总结看上一篇:全排列函数next_permutation - tb_youth的博客 - CSDN博客 https://blog.csdn.net/tb_youth/article/details/84311739
*/

猜你喜欢

转载自blog.csdn.net/tb_youth/article/details/84311826