# include <stdio.h>
# include <string.h>
char pre[100];
char ch[100];
int used[500];
void permutation(int pos, int n)
{
if ( pos == n)
{
for (int i = 0; i < n ; ++i)
printf("%c",pre[i]);
printf("\n");
return ;
}
for (int i = 0; i < n; ++i)
{
if (used[ch[i]] == 1)
{
pre[pos] = ch[i];
used[ch[i]] = 0;
permutation(pos + 1, n);
used[ch[i]] = 1;
}
}
}
int main()
{
scanf("%s",ch);
int n = strlen(ch);
for (int i = 0; i < n; ++i)
used[ch[i]] = 1;
permutation(0, n);
return 0;
}
全排列
最新推荐文章于 2024-08-04 08:42:07 发布