首页 > 其他分享 >猜名次

猜名次

时间:2023-02-03 12:31:43浏览次数:34  
标签:名次 比赛 int 第二 选手 &&

5位运动员参加了10米台跳水比赛,有人让他们预测比赛结果:

A选手说:B第二,我第三;

B选手说:我第二,E第四;

C选手说:我第一,D第二;

D选手说:C最后,我第三;

E选手说:我第四,A第一;

比赛结束后,每位选手都说对了一半,请编程确定比赛的名次。

#include<stdio.h>
int main()
{
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int e = 0;
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))
{
if(a*b*c*d*e==120)
printf("a=%d ,b=%d ,c=%d ,d=%d ,e=%d", a, b, c, d, e);
}
}
}
}
}
}
return 0;
}

标签:名次,比赛,int,第二,选手,&&
From: https://blog.51cto.com/u_15501985/6035785

相关文章

  • mysql:名次排名 (并列与不并列)
    参考:https://blog.csdn.net/weixin_40790313/article/details/87621055mysql语法笔记 2018-08-23 |阅读:次说明做后台的难免与sql接触,到目前为止搞过的sql大致都是......