STL打印全排列。next_permutation,pre_permutation.

#include 
#include 
using namespace std;
int main(){
    int n;
    while(scanf("%d",&n)&&n){
        int a[1000];
        for(int i=0;i<n;i++){
            scanf("%d",&a[i]);
        }
        sort(a,a+n);
        do{
            for(int i=0;i<n;i++)
                printf("%d ",a[i]);
            printf("\n");
        }while(next_permutation(a,a+n));
    }
    return 0;
}
#include 
using namespace std;
int main(){
    for(string s;cin>>s;cout<<endl){
        sort(s.begin(),s.end());
        for(cout<<s<<endl;next_permutation(s.begin(),s.end());cout<<s<<endl);
    }
    return 0;
}
#include 
using namespace std;
int main(){
    string a;cin>>a;
    do{
        cout<<a<<endl;
    }while(next_permutation(a.begin(),a.end()));//字典肾虚排列
    while(prev_permutation(a.begin(),a.end()));//此为字典逆序排列
    return 0;
}

你可能感兴趣的:(上机)