问题 G: C语言习题 医生值班

这里写图片描述

#include<stdio.h>
int main()
{
    int a,b,c,d,e,f=4,g;
    char s[7][20]= {"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
    int i;
    for(a=1; a<8; a++)
        for(b=1; b<8; b++)
            if(a==b)continue;
            else
                for(c=1; c<8; c++)
                    if(a!=c+1||a==c)continue;
                    else
                        for(d=1; d<8; d++)
                            if(c==d)continue;else
                            for(e=1; e<8; e++)
                                if(d!=e+2||c==d)continue;
                                else
                                    for(g=1; g<8; g++)
                                    {
                                        if((a==c+1)&&(d==e+2)&&(b==g-3)&&((f>b&&f<c)||(f<b&&f>c))&&(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)&&(d!=e)&&(d!=f)&&(d!=g)&&(f!=g))
                                        {
                                            printf("Doctor A is on duty %s.\n",s[a-1]);
                                            printf("Doctor B is on duty %s.\n",s[b-1]);
                                            printf("Doctor C is on duty %s.\n",s[c-1]);
                                            printf("Doctor D is on duty %s.\n",s[d-1]);
                                            printf("Doctor E is on duty %s.\n",s[e-1]);
                                            printf("Doctor F is on duty %s.\n",s[f-1]);
                                            printf("Doctor G is on duty %s.\n",s[g-1]);
                                        }
                                    }
    return 0;
}

可以多加几个continue语句减少循环。

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值