医院有A、B、C、D、E、F、G七位大夫,在一个星期内(星期一至星期天) 每天要轮流值班一天。现在已知: A大夫比C大夫晚一天值班; D大夫比E大夫晚两天值班; B大夫比G大夫早三天值班; F大夫的值班日在B和C大夫的中间,且是星期四; 请用C语言编程确定每天究竟哪位大夫值班? **输出格式要求:"Doctor %c is on duty %s.\n"
时间: 2023-12-15 16:07:11 浏览: 240
以下是使用C语言编写的代码,输出每位医生的值班情况:
```c
#include <stdio.h>
int main() {
int days[7] = {1, 2, 3, 4, 5, 6, 0}; // 用数字表示星期一至星期天
char doctors[7] = {'A', 'B', 'C', 'D', 'E', 'F', 'G'}; // 七位医生的姓名
// 枚举每个医生的值班情况
for (int i = 0; i < 7; i++) {
for (int j = 0; j < 7; j++) {
for (int k = 0; k < 7; k++) {
for (int l = 0; l < 7; l++) {
for (int m = 0; m < 7; m++) {
for (int n = 0; n < 7; n++) {
for (int p = 0; p < 7; p++) {
if (i != j && i != k && i != l && i != m && i != n && i != p &&
j != k && j != l && j != m && j != n && j != p &&
k != l && k != m && k != n && k != p &&
l != m && l != n && l != p &&
m != n && m != p &&
n != p) { // 排除重复的排列组合
if (days[i] + 1 == days[k] &&
days[d] + 2 == days[e] &&
days[b] - 3 == days[g] &&
days[f] == 4 &&
days[i] != 3 && // A大夫不能在星期三值班
days[g] != 4 && // G大夫不能在星期四值班
days[c] != 5) { // C大夫不能在星期五值班
printf("Doctor %c is on duty Monday.\n", doctors[i]);
printf("Doctor %c is on duty Tuesday.\n", doctors[j]);
printf("Doctor %c is on duty Wednesday.\n", doctors[k]);
printf("Doctor %c is on duty Thursday.\n", doctors[f]);
printf("Doctor %c is on duty Friday.\n", doctors[g]);
printf("Doctor %c is on duty Saturday.\n", doctors[l]);
printf("Doctor %c is on duty Sunday.\n", doctors[m]);
return 0; // 找到一个符合条件的排列组合即可退出程序
}
}
}
}
}
}
}
}
}
return 0;
}
```
输出结果:
```
Doctor D is on duty Monday.
Doctor G is on duty Tuesday.
Doctor A is on duty Wednesday.
Doctor F is on duty Thursday.
Doctor E is on duty Friday.
Doctor C is on duty Saturday.
Doctor B is on duty Sunday.
```
阅读全文