全排列 STL

#include<iostream>
#include<algorithm>
#include<stdio.h>

using namespace std;

int main()
{
    int T,i,n;
    int a[9]= {1,2,3,4,5,6,7,8,9};
    cin>>T;
    while(T--)
    {
        cin>>n;
        while(1)
        {
            for(i=0; i<n; ++i)
                cout<<a[i];
            cout<<endl;
            if(!next_permutation(a,a+n)) break;
        }
    }
    return 0;
}



全排列 ,以前比较笨  。总是出错。有模板就不容易出错了。


给一个题目链接。点击打开链接

posted @ 2016-04-16 18:36  Code-dream  阅读(146)  评论(0编辑  收藏  举报