当前位置:网站首页>Violent solution to the question of guessing the ranking
Violent solution to the question of guessing the ranking
2022-06-29 19:07:00 【Salted fish with dreams】
5 Three athletes took part in 10 Meter diving competition , They were asked to predict the outcome of the game :
A Said the player :B second , My third ;
B Said the player : I'm second ,E Fourth ;
C Said the player : I'm number one ,D second ;
D Said the player :C Last , My third ;
E Said the player : My fourth ,A First of all ;
After the game , Each player is half right , Please program to determine the position of the competition .
From the title, we can see , The problem has only one solution , also A,B,C,D,E The ranking of is divided into 1,2,3,4,5.
Then we might as well design five cycles , The variable for each cycle is set to A,B,C,D,E.
Let them each cycle 5 Take out all possible cases at once .
Add the judgment condition in the question at the end .
Pay attention here : Every condition of everyone must be judged , So use logical or “||” no
Because if logic is applied, there may be a non unique solution .
Since everyone's condition is one true and one false , Then we might as well design such a judgment :
(B == 2)+(A == 3)== 1
In this way, there is judgment on both sides , Next is the implementation of the code
#include <stdio.h>
int main()
{
int A, B, C, D, E;
for (A = 1; A <= 5; A++)
{
for (B = 1; B <= 5; B++)
{
for (C = 1; C <= 5; C++)
{
for (D = 1; D <= 5; D++)
{
for (E = 1; E <= 5; E++)
{
if ((B == 2) + (A == 3) == 1 &&
(B == 2) + (E == 4) == 1 &&
(C == 1) + (D == 2) == 1 &&
(C == 5) + (D == 3) == 1 &&
(E == 4) + (A == 1) == 1 &&
A * B * C * D * E == 120)
{
printf("A = %d,B = %d,C = %d,D = %d,E = %d\n", A, B, C, D, E);
}
}
}
}
}
}
return 0;
}
The result is A = 3,B = 1,C = 5,D = 2,E = 4.
边栏推荐
- Data analysis time series prediction
- curl下载示例
- Intégration d'outils et de cadres tiers
- Product axure9 (English version), repeater implements addition, deletion, query and modification of table contents (crud)
- Deep learning --- the weight of the three good students' scores (2)
- Third party tools and framework integration
- 程序员值得收藏的几款代码截图美化工具播
- Failed to allocate graph: myriad device is not opened
- 数据库是什么?数据库详细笔记!带你走进数据库~你想知道的这里都有!
- CentOS 7.5 install MySQL 8.0.27---yum
猜你喜欢

76.二叉树的最近公共祖先

How to use the low code platform of the Internet of things for service management?

数据仓库模型分层ODS、DWD、DWM实战

使用 OpenCV 的基于标记的增强现实

Data warehouse model layered ODS, DWD, DWM practice

企业数字化转型的点、线、面、体!

销量赶不上拿钱速度,威马赴港救急

山东大学项目实训(七)添加导航栏选择城市

Selenium的各类API方法

Failed to allocate graph: myriad device is not opened
随机推荐
Determination of concurrent number of pressure measurement
打新债线上开户安全吗
MySQL 企业级开发规范
[笔记]再笔记--边干边学Verilog HDL –008
防汛救援便携式应急通信系统解决方案
isalpha()方法介绍
Element waiting mechanism
layer. prompt
产品-Axure9(英文版),中继器(Repeater)实现表格内容的增删查改(CRUD)
C Primer Plus Chapter 12_ Storage categories, links, and memory management_ Codes and exercises
AMAZING PANDAVERSE:META”无国界,来2.0新征程激活时髦属性
PostGIS generate graphic cut
谁在抖音文玩里趁乱打劫?
Svg circle drawing path animation
Oracle11.2.0.4-Rac集群hang分析记录
誰在抖音文玩裏趁亂打劫?
揭秘!付费会员制下的那些小心机!
企业数字化转型的点、线、面、体!
MySQL Enterprise Development Specification
移动端测试