[C语言]编制排班系统源码

某生产车间有12 名员工,编号为: 001、002、003、… 012。由于工作需要,
在生产旺季取消了周末公休日,即周一至周日均要上班,因此需要实行员工轮休制度。每天安排两人休息,一星期中每人只能休息一天。每个员工可以预先自认为合适的休息日。

本程序仅供学习使用。

#include <stdio.h>			//用来输入输出
#include <time.h>			//用来辅助产生随机数
#include <stdlib.h>			//使用rand()函数
int main()	
{
    
    
	int people[12] = {
    
    0};		//用来表示这个人选的天数
	int day[7] = {
    
    0};			//用来表示这天有多少个人选中了
	int num[12] = {
    
    0},randnum;	//用来表示编号选择状态
	int input,count = 1;		//用来存放输入的天数
	int i,j;					//for循环的控制变量
	int exit;					//用来控制用户退出
	srand(time(NULL));			//随机数初始化
	randnum = (rand() % 12)+ 1;
	num[randnum-1]++;			//防止编号重复选择
	if(randnum < 10)
		printf("请编号为00%d员工选择一个自认为合适的休息日:",randnum);
	else
		printf("请编号为0%d员工选择一个自认为合适的休息日:",randnum);
	scanf("%d",&input);
	while(count < 12)									  //人数控制
	{
    
    
		while(num[randnum-1])					   //重复执行直到随机出没有选择过休息天数的人
			randnum = (rand() % 12)+ 1;
		if(input >= 1 && input <= 7 && day[input - 1] < 2)//判断是否天数已满或者输入天数不规范
		{
    
    
			count++;
			day[input - 1]++;
			num[randnum-1]++;
			people[randnum-1] = input;
		}


		if(randnum < 10)
			printf("请编号为00%d员工选择一个自认为合适的休息日:",randnum);
		else
			printf("请编号为0%d员工选择一个自认为合适的休息日:",randnum);
		scanf("%d",&input);

		if(count == 12)
			people[randnum-1] = input;
	}

	printf("\n ");
	for(i = 0 ; i < 12 ; i++)				//按照编号顺序输出
		if(i < 9)
			printf("00%d   ",i + 1);
		else
			printf("0%d   ",i + 1);
	putchar('\n');
	for(i = 0 ; i < 12 ; i++)
		printf("星期%d ",people[i]); 

	putchar('\n');
	for(i = 0;i < 7; i++)					//按照星期数输出
	{
    
    
		printf("星期%d:",i + 1);
		for(j = 0 ; j < 12 ; j++)
			if(people[j] == i + 1)
				if(j + 1 < 10)
					printf("00%d   ",j + 1);
				else
					printf("01%d   ",j - 10 + 1);
		putchar('\n');
	}

	printf("请输入0以退出程序");
	scanf("%d",&exit);
	while(exit != 0)
		scanf("%d",&exit);
	return 0;
}

在这里插入图片描述
本程序只是提供思路,请不要为了完成任务而全部抄袭,否则后果自负。

猜你喜欢

转载自blog.csdn.net/qq_28406527/article/details/121641832