结构体:枚举

2023-12-30 16:28:53

#include<iostream>  
using namespace std;
int main()
{
    enum weekday { mon, tus, wed, thu, fri, sat,sun }; //声明枚举类型 
    enum weekday day;  //定义枚举变量 
    int a, b, c, d, e, f, g, loop;  //定义整型变量 
    char ch = 'A';  //定义字符变量 
    f = thu;  //按照题意,F医生是星期四值班
    for (a = mon; a <= sun; a++)
        //需要逐个检查A医生星期几符合条件
    if (a != f)           
        //A医生值班日子不应该与F医生相同
    for (b = mon; b <= sun; b++)
        //逐个检查B医生星期几符合条件
    if (a != b)  
        //B医生值班日子不应该与A医生相同
    for (c = mon; c <= sun; c++)
        //逐个检查C医生星期几符合条件
    if ((c != a) && (c != b) && (c != f) && (a == (c + 1) % 7) && ((f > b) && (f < c) || (f > c) && (f < b)))
        //C医生值班日子不应该与A,B,F医生相同,且A比C晚1天 
    for (d = mon; d <= sun; d++)
        //逐个检查D医生星期几符合条件
    if ((d != a) && (d != b) && (d != c) && (d != f))  
        //D医生值班日子不应该与A,B,C,F医生相同
    for (e = mon; e <= sun; e++)
        //逐个检查E医生星期几符合条件
    if ((e != a) && (e != b) && (e != c) && (e != d) && (e != f) && (d == (e + 2) % 7)) 
        //E值班不应该与A,B,C,D,E,F相同,且D比E晚2天
    for (g = mon; g <= sun; g++)
        //逐个检查G医生条件
    if ((g != a) && (g != b) && (g != c) && (g != d) && (g != e) && (g != f) && (g == (b + 3) % 7))  
        //G值班不应该与A,B,C,D,E,F相同,且G与B后3天
    //符合以上条件才能执行以下工作 
    for (loop = 0; loop < 7; loop++)
    {
        cout << char(ch + loop) << "医生值班日:";
        switch (loop + 1)
        {
        case 1:day = weekday(a); break;
        case 2:day = weekday(b); break;
        case 3:day = weekday(c); break;
        case 4:day = weekday(d); break;
        case 5:day = weekday(e); break;
        case 6:day = weekday(f); break;
        case 7:day = weekday(g); break;
        }
        switch (day)
        {
        case mon:cout << "星期一" << endl; break;
        case tus:cout << "星期二" << endl; break;
        case wed:cout << "星期三" << endl; break;
        case thu:cout << "星期四" << endl; break;
        case fri:cout << "星期五" << endl; break;
        case sat:cout << "星期六" << endl; break;
        case sun:cout << "星期日" << endl; break;
        }
    }
    cout << endl;
    return 0;
}

?

?

文章来源:https://blog.csdn.net/2303_80050865/article/details/135306493
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。