In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.