void find(char *source, char *result, int n)
{
if(n==1)
{
while(*source)
printf("%s%c\n", result, *source++);
}
else
{
int i, j;
for(i=0; source != 0; i++);
for(j=0; result[j] != 0; j++);
for(; i>=n; i--)
{
result[j] = *source++;
result[j+1] = '\0';
find(source, result, n-1);
}
}
}
int main(int argc, char* argv[])
{
int const n = 3;
char *source = "ABCDE", result[n+1] = {0};
if(n>0 && strlen(source)>0 && n<=strlen(source))
find(source, result, 3);
}
组合问题(从M个不同字符中任取N个字符的所有组合)
最新推荐文章于 2023-04-09 07:34:39 发布