2人一天排班java代碼的簡單介紹

用java實現(xiàn)7個人值班,每人值班一周,從周一到周日,輪流值班

7個人值班,每人值班一周

創(chuàng)新互聯(lián)是一家專注于做網(wǎng)站、網(wǎng)站制作與策劃設計,高平網(wǎng)站建設哪家好?創(chuàng)新互聯(lián)做網(wǎng)站,專注于網(wǎng)站建設十余年,網(wǎng)設計領域的專業(yè)建站公司;建站業(yè)務涵蓋:高平等地區(qū)。高平做網(wǎng)站價格咨詢:18982081108

從周一到周日,輪流值班

需求不清楚,到底是每人值一天,還是每人值一周?

如果是每人值一天,一周七天,七人輪流,那就不需要算法了.

怎么用c語言編制一個12人排班,一天2人,一星期中每人只能休息一天。每個員工可以預先自行選擇一個天

#include stdio.h

#include stdlib.h

int sum = 0;

void restSort(int* staffs_ptr,int staff_size,int* rest_staffs_ptr,int rest_staff_size);

void print(int* rest_ptr, int rest_size);

int main() {

int init_size = 12;

int *staffs_ptr = (int*)malloc(sizeof(int) * init_size);

if (staffs_ptr != NULL) {

for (int i = 0; i init_size; i++) {

*(staffs_ptr + i) = i + 1;

}

restSort(staffs_ptr,init_size,NULL,0);

free(staffs_ptr);

printf("sum = %d\n",sum);

}

return 0;

}

void restSort(int* staffs_ptr, int staff_size, int* rest_staffs_ptr, int rest_staff_size) {

if (staff_size = 2) {

if (rest_staffs_ptr != NULL rest_staff_size 0) {

int yet_rest_staff_size = rest_staff_size + staff_size;

int* yet_rest_staffs_ptr = (int*)malloc(sizeof(int) * yet_rest_staff_size);

if (yet_rest_staffs_ptr != NULL) {

for (int rest_index = 0; rest_index rest_staff_size; rest_index++) {

yet_rest_staffs_ptr[rest_index] = rest_staffs_ptr[rest_index];

}

for (int index = rest_staff_size; index yet_rest_staff_size; index++) {

yet_rest_staffs_ptr[index] = staffs_ptr[index - rest_staff_size];

}

print(yet_rest_staffs_ptr,yet_rest_staff_size);

free(yet_rest_staffs_ptr);

}

}

else {

print(staffs_ptr,staff_size);

}

return;

}

for (int i = 0; i staff_size - 1; i++) {

for (int j = i + 1; j staff_size; j++) {

int* residue_staff_ptr = (int*)malloc(sizeof(int) * (staff_size - 2));

if (residue_staff_ptr != NULL) {

int residue_size = 0;

for (int index = 0; index staff_size; index++) {

if (index == i || index == j)

continue;

residue_staff_ptr[residue_size] = staffs_ptr[index];

residue_size++;

}

int yet_rest_staff_size = rest_staff_size + 2;

int* yet_rest_staffs_ptr = (int*)malloc(sizeof(int) * yet_rest_staff_size);

if (yet_rest_staffs_ptr != NULL) {

if (rest_staffs_ptr != NULL rest_staff_size 0) {

for (int rest_index = 0; rest_index rest_staff_size; rest_index++) {

yet_rest_staffs_ptr[rest_index] = rest_staffs_ptr[rest_index];

}

}

yet_rest_staffs_ptr[rest_staff_size] = staffs_ptr[i];

yet_rest_staffs_ptr[rest_staff_size + 1] = staffs_ptr[j];

restSort(residue_staff_ptr, residue_size,yet_rest_staffs_ptr,yet_rest_staff_size);

free(yet_rest_staffs_ptr);

}

free(residue_staff_ptr);

}

}

}

}

void print(int* rest_ptr, int rest_size) {

for (int i = 1; i = 7; i++) {

int day = 1;

for (int j = 0; j rest_size;) {

if (day == i) {

printf("星期 %d: 無 ",day);

}

else {

printf("星期 %d: %d ",day,rest_ptr[j]);

j++;

if (j rest_size) {

printf("%d ", rest_ptr[j]);

j++;

}

}

day++;

}

if (day == 7) {

printf("星期 7: 無");

}

printf("\n");

sum++;

}

}

三人上班每天2人 排班

假如這樣排列你們的時刻表 17AB 18BC 19AC 20AB 21BC 22AC 23AB 24BC

18號假如剛好你休假 19號就要跟21號的B換 20號就要跟24號的C換班

但是換之前和換之后你都要連續(xù)工作好幾天

如何用java實現(xiàn)人員自動排班的問題

應該用不上什么線程,一次性把所有的班都排好

六個元素的數(shù)組

兩個指針,一個是工作日當值人,一個是周末當值人,初始都是0

從今天開始到指定某一天,譬如年底

int idx_workday =0;

int idx_weekend =0;

ArrayList assignment = new ArrayList();

day = today;

while(day不是年底){

int i;

if (day is workday){

i = idx_workday++;

assignment.add(i);

if (idx_workday 5) idx_workday = 0;

}else{

i = idx_weekend++;

assignment.add(i);

if (idx_weekend 5) idx_weekend= 0;

}

}

output assignment

新聞名稱:2人一天排班java代碼的簡單介紹
本文URL:http://www.muchs.cn/article32/hcpgpc.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供軟件開發(fā)、虛擬主機、標簽優(yōu)化、企業(yè)建站、網(wǎng)站設計、網(wǎng)站建設

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

小程序開發(fā)