当前位置:网站首页>C语言题解:谁是凶手!
C语言题解:谁是凶手!
2022-08-11 04:52:00 【某某小卢】
完整代码在最后哦!
题目描述
日本某地发生了一件谋杀案,警察通过排查确定杀人凶手必为4个嫌疑犯的一个。
以下为4个嫌疑犯的供词:
A说:不是我。
B说:是C。
C说:是D。
D说:C在胡说
已知3个人说了真话,1个人说的是假话。
现在请根据这些信息,写一个程序来确定到底谁是凶手。
解题思路
本题,只有一个人说了谎话,3个人说真话,我们可以让每判断一次说真话返回1,三次真话就是三个1等于3.我们可以利用每一次假设某一个人为凶手来判断每个人说的话是否为真话。所以利用for语句从凶手a到凶手d,每次判断就ok了

完整代码
#include<stdio.h>
int main()
{
char m;
for (char i = 'a'; i <= 'd'; i++)
{
if ((i != 'a') + (i == 'c') + (i == 'd') + (i != 'd') == 3)
{
printf("%c", i);
}
}
return 0;
}边栏推荐
猜你喜欢

交换机和路由器技术-32-命名ACL

Three 】 【 yolov7 series of actual combat from 0 to build training data sets

Self-research capability was recognized again, and Tencent Cloud Database was included in the Forrester Translytical report

干货:服务器网卡组技术原理与实践

Object Creation and Display Transformation

论文笔记:Bag of Tricks for Long-Tailed Visual Recognition with Deep Convolutional Neural Networks

交换机和路由器技术-24-OSPF单区域配置

网络技能树

Dry goods: The principle and practice of server network card group technology

To break the bottleneck of transactional work, the gentleman signs the electronic contract to release the "source power" of HR!
随机推荐
JwsManager service interface implementation class - the jni implementation
自研能力再获认可,腾讯云数据库入选 Forrester Translytical 报告
简历里写了会代码,却依然过不了面试这一关
About the pom.xml file
Listen to pull out U disk inserted into the message, U disk drive
论文笔记:Bag of Tricks for Long-Tailed Visual Recognition with Deep Convolutional Neural Networks
直播平台开发,Flutter,Drawer侧滑
Switch---Spanning Tree---Three-layer Architecture Summary
"239 Sliding Window Maximum Value" on the 16th day of LeetCode brushing
洛谷P4324 扭动的回文串
Use Navicat Premium to export database table structure information to Excel
「转」“搜索”的原理,架构,实现,实践,面试不用再怕了
源代码加密技术浅析
Mysql:设置主键自动增长起始值
交换机和路由器技术-32-命名ACL
How to switch Green Shield encryption to IP-Guard encryption smoothly
交换机和路由器技术-36-端口镜像
Redis: Solve the problem of modifying the same key with distributed high concurrency
在 关闭页面/卸载(unload)文档 之前向服务器发送请求
关于数据分页显示