089.配对新郎和新娘

举报
C语言与CPP编程 发表于 2022/05/03 22:37:07 2022/05/03
【摘要】 #include<stdio.h>void main(){ int x,y,z; clrscr(); puts("****************************************************************"); puts("* This program is t...

  
  1. #include<stdio.h>
  2. void main()
  3. {
  4. int x,y,z;
  5. clrscr();
  6. puts("****************************************************************");
  7. puts("* This program is to solve Problem of Bridegroom and Bride. *");
  8. puts("* The Problem is as follows: Someone goes to 3 couples lovers' *");
  9. puts("* wedding. The bridegrooms are A,B,C and the brides are X,Y,Z. *");
  10. puts("* He wants to know who marries who and asks them. A says he *");
  11. puts("* will marry to X, X says her fiance is C, C says he will marry*");
  12. puts("* to Z. The man knows that they are all kidding. What they said*");
  13. puts("* is not true. So try to find who will marry to who? *");
  14. puts("****************************************************************");
  15. puts(" >> The solutions are:");
  16. printf("---------------------------------------------\n");
  17. for(x=1;x<=3;x++) /*穷举x的全部可能配偶*/
  18. for(y=1;y<=3;y++) /*穷举y的全部可能配偶*/
  19. for(z=1;z<=3;z++) /*穷举z的全部可能配偶*/
  20. if(x!=1&&x!=3&&z!=3&&x!=y&&x!=z&&y!=z) /*判断配偶是否满足题意*/
  21. {
  22. printf(" X will marry to %c.\n",'A'+x-1); /*打印判断结果*/
  23. printf(" Y will marry to %c.\n",'A'+y-1);
  24. printf(" Z will marry to %c.\n",'A'+z-1);
  25. }
  26. printf("---------------------------------------------\n");
  27. printf(" Press any key to quit...");
  28. getch();
  29. }

文章来源: blog.csdn.net,作者:程序员编程指南,版权归原作者所有,如需转载,请联系作者。

原文链接:blog.csdn.net/weixin_41055260/article/details/124536581

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。