黄浩老师cpp平时作业(三)医生值班

#include<iostream>
using namespace std;

int main()
{
    char str[7][10] = { "Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday" };
    enum week { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday };
    for (int a = Sunday; a <= Saturday; a++)
    {
        for (int b = Sunday; b <= Saturday; b++)
        {
            for (int c = Sunday; c <= Saturday; c++)
            {
                for (int d = Sunday; d <= Saturday; d++)
                {
                    for (int e = Sunday; e <= Saturday; e++)
                    {
                        for (int g = Sunday; g <= Saturday; g++)
                        {
                            int f = Thursday;
                            if ((a == (c + 1) % 7) && (d == (e + 2) % 7) && (g == (b + 3) % 7) && ((f > b) && (f < c) || (f > c) && (f < b)) && (a != b) && (a != c) && (a != d) && (a != e) && (a != f) && (a != g) && (b != c) && (b != d) && (b != e) && (b != f) && (b != g) && (c != d) && (c != e) && (c != f) && (c != g) && (c != e) && (d != e) && (d != f) && (d != g) && (e != f) && (e != g) && (f != g))
                            {
                                cout << "Doctor A is on duty " << str[a] << '.' << endl;
                                cout << "Doctor B is on duty " << str[b] << '.' << endl;
                                cout << "Doctor C is on duty " << str[c] << '.' << endl;
                                cout << "Doctor D is on duty " << str[d] << '.' << endl;
                                cout << "Doctor E is on duty " << str[e] << '.' << endl;
                                cout << "Doctor F is on duty " << str[f] << '.' << endl;
                                cout << "Doctor G is on duty " << str[g] << '.' << endl;
                                cout << endl;
                            }
                        }
                    }
                }
            }
        }
    }

    return 0;
}

医生值班是一道看起来像小学逻辑奥数题的枚举变量应用练习题,整体思路就是把每种情况用枚举变量列一遍,然后把它的要求翻译成一个长长长长的条件语句。

这样可以输出不止一种情况。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值