//.cpp : Defines the entry point for the console application.
//
#include "string.h"
#include <stdio.h>
char *WEEK[] = { "星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" }; struct demand
{
char name[];
int day[];
} man[]; int main()
{
int IsChecked(int p[]);
int t = , j, ren[];
long i, k;
printf("****************保安值班系统****************\n");
printf("请各位分别输入各自合适的休假日\n");
printf("如赵保安选择星期二和星期三,就输入2 3 然后回车\n");
printf("数字0 1 2 3 4 5 6分别代表\n星期天 星期一 星期二 星期三 星期四 星期五 星期六\n");
printf("注意要输入星期天请输入数字0 \n");
for (i = ; i<; i++)
{
printf("请第%d个人输入\n", i + );
for (k = ; k<; k++)
{
//scanf("%d",&man[i].day[k]);
char c;
scanf("%c", &c);
if (c == '\n')
{
break;//读取到换行符,即回车,退出循环。
}
else if (c >= && c <= )
{
man[i].day[k] = (int)(c - '');
//printf("%d %c\n", k, c);
}
else if (c == ' ')
{
k--;
}
} // printf("你输入的day是:");
// for(k=0;k<7;k++)
// {
// printf("%d ",man[i].day[k]);
// }
// printf("\n"); printf("你输入的day是:");
for (int m = ; m < k; m++)
{
printf("%d ", man[i].day[m]);
}
for (int m = k; m < ; ++m)
{
man[i].day[m] = ;
printf("%d ", man[i].day[m]);
}
printf("\n");
} printf("**********************************************");
printf("\n* 赵, 钱, 孙, 李, 周 , 吴, 陈 , *\n");
printf("*--------------------------------------------*\n");
printf("");
for (i = ; i < ; ++i)
{
for (j = ; j<; ++j)
{
ren[j] = (i >> ( * j)) & ; //*通过这个循环,穷尽0-7在数组中所有的排列组合方式*//
} if (!(ren[] == man[].day[] || ren[] == man[].day[] || ren[] == man[].day[] || ren[] == man[].day[] || ren[] == man[].day[] || ren[] == man[].day[] || ren[] == man[].day[]))
continue;//*如果赵保安不是休周二或周四,就不用循环了。*//
else if (!(ren[] == man[].day[] || ren[] == man[].day[] || ren[] == man[].day[] || ren[] == man[].day[] || ren[] == man[].day[] || ren[] == man[].day[] || ren[] == man[].day[]))
continue; //*如果钱保安不是休周一或周六,就不用循环了。*//
else if (!(ren[] == man[].day[] || ren[] == man[].day[] || ren[] == man[].day[] || ren[] == man[].day[] || ren[] == man[].day[] || ren[] == man[].day[] || ren[] == man[].day[]))
continue; //*如果孙保安不是休周三或周日,就不用循环了。*//
else if (!(ren[] == man[].day[] || ren[] == man[].day[] || ren[] == man[].day[] || ren[] == man[].day[] || ren[] == man[].day[] || ren[] == man[].day[] || ren[] == man[].day[]))
continue; //*如果李保安不是休周五,就不用循环了。*//
else if (!(ren[] == man[].day[] || ren[] == man[].day[] || ren[] == man[].day[] || ren[] == man[].day[] || ren[] == man[].day[] || ren[] == man[].day[] || ren[] == man[].day[]))
continue; //*如果周保安不是休周一或周四或周六,就不用循环了。*//
else if (!(ren[] == man[].day[] || ren[] == man[].day[] || ren[] == man[].day[] || ren[] == man[].day[] || ren[] == man[].day[] || ren[] == man[].day[] || ren[] == man[].day[]))
continue; //*如果吴保安不是休周二或周五,就不用循环了。*//
else if (!(ren[] == man[].day[] || ren[] == man[].day[] || ren[] == man[].day[] || ren[] == man[].day[] || ren[] == man[].day[] || ren[] == man[].day[] || ren[] == man[].day[]))
continue; //*如果陈保安不是休周三或周六或周日,就不用循环了。*//
else if (!IsChecked(ren))
continue; //*至此,所有的保安可按他们的愿望休假,但是此时的方案可能有两个人同休一天的*//
//*情况发生,因此用这个函数排除,如果0-6这七个数字(一周七天)任何一个包含在数组中则此次匹配失败。*//
for (j = ; j<; ++j)
{
printf("%s ", WEEK[ren[j]]);
} printf(" *");
printf("\n"); //*输出成功匹配方案*//
++t; //*记录成功匹配个数*//
} printf("*--------------------------------------------*");
printf("\n* %d 种 情 况! *", t); //*输出成功匹配方案个数*//
printf("\n**********************************************");
getchar();
return ;
} int IsChecked(int p[])
{
int i, j;
for (i = ; i<; ++i)
{
for (j = ; j< && p[j] != i; ++j); /*从0到6循环,如果数组中缺少0-6的任何一位数字,则返回0,如果0-6都有,则返回。*/
if (j == )
return ;
}
return ; //*这个函数的作用是确保0-6这7个数字均包含在该数组中*//
}

C语言课程设计-保安值班系统支持任意输入保安值班时间-LMLPHP

05-11 22:11