输入一个字符串,输出字符串的全排列
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
#define N 15
char str[N];
char str1[N];
char visit[N] = { 0 };
void dfs(int depth, int len)
{
if (depth > len)
{
str1[len+1] = '\0';
cout << str1+1<<" ";
cout << endl;
}
else
{
for (int i = 1; i <= len; i++)
{
if (!visit[i])
{
str1[depth] = str[i-1];
visit[i] = 1;
dfs(depth + 1, len);
visit[i] = 0;
}
}
}
}
int main()
{
cin >> str;
int len = strlen(str);
sort(str, str + len);
dfs(1, len);
return 0;
}