逻辑推理
 1 <!DOCTYPE html>
 2 <html lang="en">
 3   <head>
 4     <meta charset="UTF-8" />
 5     <title>逻辑推理</title>
 6   </head>
 7   <body>
 8     <script>
 9       /*
10        日本某地发生了一起谋杀案,警察通过排查确定杀人凶手为4个嫌疑犯的一个,以下为四个嫌疑犯的供词
11        A说:不是我;
12        B说:是C;
13        C说:是D;
14        D说:C在胡说;
15        已知三个人说了真话,一个人说了假话,请编写代码找出凶手!
16        */
17       var list = ["A", "B", "C", "D"];
18       for (let i = 0; i <= 3; i++) {
19         if ((list[i] != "A") + (list[i] == "C") + (list[i] == "D") + (list[i] != "D") == 3) {
20           document.write("凶手是" + list[i]);
21         }
22       }
23     </script>
24   </body>
25 </html>

 

Copyright © 2024 lx挽月
Powered by .NET 9.0 on Kubernetes