打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
090.约瑟夫问题
#include<stdio.h>
void main()
{
    int x,y,z;
    clrscr();
    puts("****************************************************************");
    puts("*  This program is to solve Problem of Bridegroom and Bride.   *");
    puts("* The Problem is as follows: Someone goes to 3 couples lovers' *");
    puts("* wedding. The bridegrooms are A,B,C and the brides are X,Y,Z. *");
    puts("* He wants to know who marries who and asks them. A says he    *");
    puts("* will marry to X, X says her fiance is C, C says he will marry*");
    puts("* to Z. The man knows that they are all kidding. What they said*");
    puts("* is not true. So try to find who will marry to who?           *");
    puts("****************************************************************");
    puts(" >> The solutions are:");
    printf("---------------------------------------------\n");
    for(x=1;x<=3;x++)          /*穷举x的全部可能配偶*/
        for(y=1;y<=3;y++)      /*穷举y的全部可能配偶*/
            for(z=1;z<=3;z++)    /*穷举z的全部可能配偶*/
                if(x!=1&&x!=3&&z!=3&&x!=y&&x!=z&&y!=z)  /*判断配偶是否满足题意*/
                {
		    printf(" X will marry to %c.\n",'A'+x-1);    /*打印判断结果*/
		    printf(" Y will marry to %c.\n",'A'+y-1);
		    printf(" Z will marry to %c.\n",'A'+z-1);
                }
    printf("---------------------------------------------\n");
    printf(" Press any key to quit...");
    getch();
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
【法律翻译:英译汉】 Frenchman wins legal right to marry his ex-stepmother
为什么总有人说,到了年纪就一定要结婚生子?
"COMPLETE" and "FINISH"
诙谐搞笑的英语谚语
中考英语语法综合练习题1.marry用法讲解marry sb 和
Marry U
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服