You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
1.3 KiB

6 years ago
#include <stdio.h>
int n = 0;
int rest[7][7];
void swap(int *a, int *b)
{
int m;
m = *a;
*a = *b;
*b = m;
}
void perm(int list[], int k, int m)
{
int i;
int j;
if(k > m)
{
for (i=0; i<7; i++)
{
for (j=0; j<7; j++)
{
if (rest[i][j] == -1)
return;
if (rest[i][j] != list[i])
continue;
if (rest[i][j] == list[i])
break;
}
}
n++;
printf("Solution: %d\n", n);
printf("<EFBFBD><EFBFBD> Ǯ <20><> <20><> <20><> <20><> <20><>\n");
for(i = 0; i <= m; i++)
{
switch (list[i])
{
case 1: printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ ");
break;
case 2: printf("<EFBFBD><EFBFBD><EFBFBD>ڶ<EFBFBD> ");
break;
case 3: printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ");
break;
case 4: printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ");
break;
case 5: printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ");
break;
case 6: printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ");
break;
case 7: printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ");
break;
default:
break;
}
}
printf("\n\n\n");
}
else
{
for(i = k; i <= m; i++)
{
swap(&list[k], &list[i]);
perm(list, k + 1, m);
swap(&list[k], &list[i]);
}
}
}
int main()
{
int list[] = {1, 2, 3, 4, 5, 6, 7};
int i, j;
char ss[7][20]={"<EFBFBD><EFBFBD>","Ǯ","<EFBFBD><EFBFBD>","<EFBFBD><EFBFBD>","<EFBFBD><EFBFBD>","<EFBFBD><EFBFBD>","<EFBFBD><EFBFBD>"};
printf("===========================<3D><>ӭʹ<D3AD><CAB9><EFBFBD>Ű<EFBFBD>ϵͳ===================================\n");
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>,ÿ<><C3BF><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>˵<EFBFBD><CBB5><EFBFBD>Ϣʱ<CFA2><EFBFBD><E4A3AC><EFBFBD><EFBFBD>-1<>󰴻س<F3B0B4BB>\n");
for(i = 0; i < 7; i++)
{
printf("%s<><73>",ss[i]);
for(j = 0; j < 7; j++)
{
scanf("%d", &rest[i][j]);
if(rest[i][j] == -1)
break;
}
}
printf("\n\n\n");
perm(list, 0, 6);
printf("<EFBFBD><EFBFBD><EFBFBD>ܵķ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:%d<><64>", n);
getchar();
return 0;
}