全排列模板(利用c++函数)

next_permutation,别忘记加头文件(#include<algorithm> ),还有sort排序(不然有个别数据无法输出)。

#include<stdio.h> 
#include<string.h> 
#include<algorithm> 
using namespace std; 
int main() 
{ 
    char s[300]; 
    int i,l; 
    while(scanf("%s",s)!=EOF) 
    { 
        sort(s,s+strlen(s)); 
        l=strlen(s); 
        do{ 
            puts(s);  
        }while(next_permutation(s,s+l)); 
    } 
    return 0; 
} 

猜你喜欢

转载自blog.csdn.net/qq_42761817/article/details/81430668