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.
78 lines
1.7 KiB
78 lines
1.7 KiB
#include "stdio.h"
|
|
int n=0;
|
|
int rest[7][7];//休息的可能时间、
|
|
void swap(int *a,int *b)//实现交换
|
|
{
|
|
int m;
|
|
m=*a; *a=*b;
|
|
*b=m;
|
|
}
|
|
//0 6
|
|
void perm(int list[],int k,int m)//把输入的每个人的可能休息时间传给函数、
|
|
{
|
|
int i; int j;
|
|
if(k>m)//当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("赵 钱 孙 李 周 吴 陈\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");
|
|
}
|
|
else//当K<=m的时候
|
|
{
|
|
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};//一周的7天、
|
|
int i,j;
|
|
char ss[7][20]={"赵","钱","孙","李","周","吴","陈"};
|
|
printf("============================ 欢 迎 使 用 排 班 系 统 ============================");
|
|
printf("请输入下列人选择休息的可能时间:\n");
|
|
for(i=0;i<7;i++)
|
|
{
|
|
printf("%s: ",ss[i]);
|
|
for(j=0;j<7;j++)//输入可能的休息时间、
|
|
{
|
|
scanf("%d",&rest[i][j]);
|
|
if(rest[i][j]==-1) break;//当输入的休息时间位-1时、开始下一个人的可能休息时间
|
|
}
|
|
}
|
|
printf("\n\n\n");
|
|
perm(list,0,6);
|
|
getchar();
|
|
getchar();//getchar()函数也会获取你输入的回车字符'\n'
|
|
return 0;
|
|
}
|
|
|