能力值:
( LV3,RANK:20 )
|
-
-
2 楼
算法没学好,只会递归来穷举密码
|
能力值:
( LV2,RANK:10 )
|
-
-
3 楼
全排列(perm)算法:
#include <stdio.h>
#include <math.h>
void swap(char *str, int a, int b);
void perm(char *str, int n, int left, int right);
int main()
{
char test_str[] = {"abc"};
perm(test_str, 3, 0, 2);
return 0;
}
void perm(char *str, int n, int left, int right)
{
int i;
if(left >= right)
{
for(i = 0; i < n; ++i)
printf("%c ", str[i]);
putchar('\n');
}
else
{
for(i = left; i <= right; ++i)
{
swap(str, left, i);
perm(str, n, left+1, right);
swap(str, left, i);
}
}
}
void swap(char *str, int a, int b)
{
char temp;
temp = str[a];
str[a] = str[b];
str[b] = temp;
}
|
|
|