-5
我想如果我输入的输入abc
它给我输出bca
cab
abc
排列组合
#include<stdio.h>
#include<string.h>
int main()
{
char str[15];
int i,j,n;
printf("Enter a string");
scanf("%s",str);
n=strlen(str);
for(i=0;i<n;i++)
{
str[n]=str[0];
for(j=0;j<n;j++)
{
str[j]=str[j-1];
}
str[n]='\0';
printf("\n %s \n",str);
}
return 0;
}
但我想一个程序,它给我的所有可能的组合,其产生的字符串的一些组合方案字符串 那么我需要做些什么改变?
http://en.wikipedia.org/wiki/Permutation#Algorithms_to_generate_permutations – 2010-08-22 23:41:31
的http://计算器。 com/questions/361/generate-list-of-all-possible-permutations-of-a-string – 2010-08-22 23:42:34
除非'str'中的字母数量固定为一个小值(和14代码一样,代码不是很小),你最好在某个时候使用递归,否则它可能会变得乏味。 – 2010-08-22 23:42:48