当前位置:网站首页>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;
}边栏推荐
- Application of Identification Cryptography in IMS Network
- WPF DataGrid 使用数据模板(2)
- 交换机和路由器技术-33-静态NAT
- Redis deletes keys in batches according to regular rules
- 增加PRODUCT_BOOT_JARS及类 提供jar包给应用
- 延长经济保险(jeecgboot)
- Layered Architecture & SOA Architecture
- 如何缓解压力、拒绝内耗【1】
- I wrote some code in my resume, but I still can't pass the interview
- 交换机--- 生成树--三层架构总结
猜你喜欢

Word2021 中的图片保存后就变模糊了

应用层协议——DNS

Optimization is a kind of habit low starting point is the "standing near the critical"

Selenium自动化测试框架工作原理你明白了吗?

Switch---Spanning Tree---Three-layer Architecture Summary

交换机和路由器技术-27-OSPF路由重分发

论文笔记:BBN: Bilateral-Branch Network with Cumulative Learningfor Long-Tailed Visual Recognition

svg-icon的使用方法(svg-sprite-loader插件)

交换机和路由器技术-34-动态NAT

交换机和路由器技术-30-标准ACL
随机推荐
Summary of c language fprintf, fscanf, sscanf and sprintf function knowledge points
智能指针笔记
"239 Sliding Window Maximum Value" on the 16th day of LeetCode brushing
Redis:解决分布式高并发修改同一个Key的问题
[Note] Is the value of BatchSize the bigger the better?
澳大利亚网络空间安全体系建设论析
交换机和路由器技术-24-OSPF单区域配置
直播平台开发,Flutter,Drawer侧滑
The principle, architecture, implementation, practice of "transfer" and "search", no need to be afraid of interviews
The basics of binary heap~
洛谷P5139 z小f的函数
嵌入式分享合集33
交换机和路由器技术-28-OSPF的NSSA区域
【服务器安装Redis】Centos7离线安装redis
Jetson Orin platform 4-16 channel GMSL2/GSML1 camera acquisition kit recommended
破解事务性工作瓶颈,君子签电子合同释放HR“源动力”!
洛谷P1763 埃及分数
绿盾加密如何顺利切换成IP-Guard加密
交换机和路由器技术-25-OSPF多区域配置
The sword refers to offer_abstract modeling capabilities