算法【婚礼上的谎言】

Q:在这里插入图片描述
A:

所有人说的都是谎话,所以3个条件 就是
a != 0 && 0 != c && c != 2 (用 a=0 表示新郎a和x结婚,同理不结婚则表示a!=0)
同时隐含条件就是3个新郎不能互为配偶(也就是说两个新娘不可嫁给一个人)
所以a!=b && a!=c && b!=c

#include<iostream>

using namespace std;

int main() {
    //groom
    int a, b, c;
    //bride 0 1 2
    char X = 'X';
    for (a = 0;  a<3 ; a++) {
        for (b = 0;  b<3 ; b++) {
            for (c = 0;  c<3 ; c++) {
                //a is not married to X, X is not married to c, c is not married to Z
                if(a != 0 && 0 != c && c != 2 && a!=b && a!=c && b!=c){
                    cout<<"A married "<<(char)(X+a)<<endl;
                    cout<<"B married "<<(char)(X+b)<<endl;
                    cout<<"C married "<<(char)(X+c)<<endl;
                }
            }
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值