zoukankan      html  css  js  c++  java
  • 前天笔试的一道题[4个窃贼]

    代码
    using System;
    using System.Collections.Generic;
    using System.Text;
    /*
    公安人员审问四名窃贼嫌疑犯。已知,这四人当中仅有一名是窃贼,还知道这四人中每人要么是诚实的,要么总是说谎的。在回答公安人员的问题中:
    甲说:“乙没有偷,是丁偷的。”
    乙说:“我没有偷,是丙便的。”
    丙说:“甲没有偷,是乙偷的。”
    丁说:“我没有偷。”
    请根据这四人的答话判断谁是盗窃者。
    */
    namespace ConsoleApplication1
    {
    class Program
    {
    static void Main(string[] args)
    {
    //假设窃贼为1,,非窃贼为0,递归假设各种情况
    int[] a = new int[4];
    for (int i = 0; i < 4;i++ )
    {
    for (int j = 0; j < 4; j++)
    {
    if (j == i)
    {
    a[j]
    = 1;
    }
    else
    {
    a[j]
    = 0;
    }
    }

    //对每一项递归的情况进行判断
    if ((a[1] + a[3] == 1) && (a[1] + a[2] == 1) && (a[0] + a[1] == 1))//其中甲、乙、丙三个人无论有没有说谎,他们话里所描述的人必有一个是窃贼
    {
    for (int k = 0; k < 4; k++)
    {
    //;
    string strDisplayName="";
    if (a[k] == 1)
    {
    switch (a[k])
    {
    case 0:
    strDisplayName
    = "";
    break;
    case 1:
    strDisplayName
    = "";
    break;
    case 2:
    strDisplayName
    = "";
    break;
    case 3:
    strDisplayName
    = "";
    break;
    }
    Console.WriteLine(
    "我觉得吧犯人应该是:{0}", strDisplayName);
    }
    }
    }
    }
    }
    }
    }
  • 相关阅读:
    windows 7 codepage id name 名称
    最大团
    三分的多种写法及对应的精度 三分套三分原理
    AC自动机
    c++ queue
    lca 欧拉序+rmq(st) 欧拉序+rmq(线段树) 离线dfs 倍增
    node *p,*q
    dfs序和欧拉序
    P3861 8月月赛A
    洛谷P3862 8月月赛B
  • 原文地址:https://www.cnblogs.com/Cavalry/p/1745245.html
Copyright © 2011-2022 走看看