#include <stdio.h>
char str[100] = {0};
char out[100] = {0};
int len = 0;
void get_size()
{
while (str[len] != 0)
{
len++;
}
}
void sort()
{
int i, j;
char tmp;
for (i = 0; i < len - 1; i++)
for (j = i + 1; j < len; j++)
{
if (str[i] > str[j])
{
tmp = str[i];
str[i] = str[j];
str[j] = tmp;
}
}
}
void pailie(int loc)
{
int i;
char tmp;
for (i = 0; i < len; i++)
{
if (i > 0 && str[i] == str[i-1]) ;
else if (str[i] != '#')
{
tmp = str[i];
out[loc] = str[i];
str[i] = '#';
if (loc == len - 1)
{
out[len] = 0;
puts(out);
}
else
{
pailie(loc + 1);
}
str[i] = tmp;
}
}
}
void main()
{
gets(str);
get_size();
sort();
pailie(0);
}
重复数全排列的递归实现
最新推荐文章于 2023-01-30 16:02:06 发布