#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <windows.h>
int n = 0;
int rest[7][7];
char name[10][3]={"赵","钱","孙","李","周","吴","陈","郑","马","陈"};
int who[7];
void Get_Who()
{
int i,j,flag;
srand(time(NULL));
for(i=0;i<7;i++)
{
do
{
flag=0;
who[i]=rand()%10;
for(j=0;j<i;j++)
{
if(who[i]==who[j])
{
flag=1;
break;
}
}
}while(flag);
}
}
void swap(int *a, int *b)
{
int m;
m = *a;
*a = *b;
*b = m;
}
void perm(int list[], int k, int m)
{
int i,s;
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);
for(s=0;s<7;s++)
{
printf("%6s",name[who[s]]);
}
printf("\n");
printf("=============================================================\n");
for(i = 0; i <= m; i++)
{
switch (list[i])
{
case 1: printf("星期一 ");
break;
case 2: printf("星期二 ");
break;
case 3: printf("星期三 ");
break;
case 4: printf("星期四 ");
break;
case 5: printf("星期五 ");
break;
case 6: printf("星期六 ");
break;
case 7: printf("星期日 ");
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;
Get_Who();
for(i = 0; i < 7; i++)
{
printf("%6s", name[who[i]]);
}
printf("\n");
for(i = 0; i < 7; i++)
{
printf("%s 选择休息日:\n", name[who[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("总计:%d\n", n);
getchar();
getchar();
return 0;
}
排班系统
最新推荐文章于 2024-07-27 18:16:42 发布