089.配对新郎和新娘

Posted 程序员编程指南

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了089.配对新郎和新娘相关的知识,希望对你有一定的参考价值。

#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();

以上是关于089.配对新郎和新娘的主要内容,如果未能解决你的问题,请参考以下文章

javascript新郎新娘问题

三对情侣结婚,三个新郎为A,B,C,三个新娘为X,Y,Z,根据以下话语: A说:我将和X结婚。 X

5.8新娘与新郎

走!去接淘系的新郎新娘们回娘家了!| 510阿里日

硬核!两个博士结婚,接亲时新娘给新郎摆了盘棋局:你赢了再娶我!

不容易系列之——考新郎