当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
Jetson Orin platform 4-16 channel GMSL2/GSML1 camera acquisition kit recommended
Merkel Studio--OpenEuler Training Notes (1)
0 Basic software test for career change, self-study for 3 months, 12k*13 salary offer
【电商运营】社交媒体营销策略该如何制定?
ALSA音频架构 -- snd_pcm_open函数分析
How to switch Green Shield encryption to IP-Guard encryption smoothly
Switches and routers technology - 21 - RIP routing protocol
0基础转行软件测试,自学3个月,浅拿12k*13薪offer
交换机和路由器技术-28-OSPF的NSSA区域
交换机和路由器技术-24-OSPF单区域配置
随机推荐
How to switch Green Shield encryption to IP-Guard encryption smoothly
"125 Palindrome Verification" of the 10th day string series of LeetCode brushing questions
洛谷P2580 于是他错误的点名开始了
form表单提交数据库中文变成问号
【实战场景】商城-折扣活动设计方案
【ImageNet】数据集1000个类的名称
The principle, architecture, implementation, practice of "transfer" and "search", no need to be afraid of interviews
洛谷P5139 z小f的函数
交换机和路由器技术-27-OSPF路由重分发
交换机和路由器技术-34-动态NAT
交换机--- 生成树--三层架构总结
洛谷P1196 银河英雄传说
破解事务性工作瓶颈,君子签电子合同释放HR“源动力”!
IP-Guard如何禁止运行U盘程序
MQ框架应用比较
redis按照正则批量删除key
Redis: Solve the problem of modifying the same key with distributed high concurrency
Mysql中事件和定时任务
1815. Get the maximum number of groups of fresh donuts state compression
洛谷P4324 扭动的回文串