In addition to Weibo, there is also WeChat
Please pay attention

WeChat public account
Shulou
2025-11-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, the editor will bring you about how to guess the murderer in C language and the realization of similar topics. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
Description:
There was a murder somewhere in Japan and the police determined by investigation that the murderer must be one of four suspects.
Here are the confessions of the four suspects:
A said: not me.
B said: it's C.
C said: it's D.
D said: C is talking nonsense.
Three people are known to be telling the truth and one is telling a lie.
Now, based on this information, write a program to determine who the killer is.
Thinking and analysis:
Students who have never done a similar topic may be a little confused when they see this question for the first time. Then start thinking about assumptions, permutations, enumerations, and so on. But the result of the code for this question will surprise you.
First of all, the first thing to consider is how to represent the words of these four people in code. We define a char variable killer to represent the killer. The best thing you can think of is that if what someone says is true, put his result as 1 (similar to the bool type), otherwise it is 0. This idea is correct. A says, not A, then it can be expressed as killer! ='A'. If the judgment is true, he will return 1, otherwise, he will return 0. Similarly, the words of the other three people can be expressed in the same way. Finally, according to the fact that three people told the truth, one person told a lie and learned that the sum of returns was 3. For example, if we assume that An is the killer, then according to what the four people said, A told a lie, and B also told a lie, which is not consistent with the conditions. After this, only the case of A has been judged, and the situation of BMagol Cpene D has not been judged yet, it only needs to add a loop.
The C language code is as follows:
# include int main (void) {char killer = 'Aids; for (killer =' Aids; killer)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope





About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.