求字符串中所有字符的组合,字符顺序无关,如hd和dh是同一个组合
#include
#include
char str[5]="hard";
char out[5];
int len;
void getBand(char s[], int n, int m)
{
if (str[len-n] == '\0')
{
out[m]='\0';
printf("%s\n", out);
return;
}
getBand(str, n-1, m);
out[m++]=str[len-n];
getBand(str, n-1, m);
}
int main()
{
len = strlen(str);
getBand(str, len, 0);
return 0;
}
阅读(1122) | 评论(0) | 转发(1) |