[java版]5位跳水高手参加10米高台跳水决赛,有好事者让5人据实力预测比赛结果...

public class T {
	public static void main(String[] args) {

		boolean[] isRight = new boolean[5]; // 分别代表各位的逻辑判断
		int[] personValue = new int[5]; // 分别代表5位选手的名次
		String[] person = new String[] { "A", "B", "C", "D", "E" };// 分别代表5位选手
		for (personValue[0] = 1; personValue[0] <= 5; personValue[0]++)
			for (personValue[1] = 1; personValue[1] <= 5; personValue[1]++)
				for (personValue[2] = 1; personValue[2] <= 5; personValue[2]++)
					for (personValue[3] = 1; personValue[3] <= 5; personValue[3]++)
						for (personValue[4] = 1; personValue[4] <= 5; personValue[4]++) {
							isRight[0] = ((personValue[1] == 2) && (!(personValue[0] == 3)))
									|| ((!(personValue[1] == 2)) && (personValue[0] == 3));
							isRight[1] = ((personValue[1] == 2) && (!(personValue[4] == 4)))
									|| ((!(personValue[1] == 2)) && (personValue[4] == 4));
							isRight[2] = ((personValue[2] == 1) && (!(personValue[3] == 2)))
									|| ((!(personValue[2] == 1)) && (personValue[3] == 2));
							isRight[3] = ((personValue[2] == 5) && (!(personValue[3] == 3)))
									|| ((!(personValue[2] == 5)) && (personValue[3] == 3));
							isRight[4] = ((personValue[4] == 4) && (!(personValue[0] == 1)))
									|| ((!(personValue[4] == 4)) && (personValue[0] == 1));
							if (((isRight[0] && isRight[1] && isRight[2]
									&& isRight[3] && isRight[4]) == true)
									&& (personValue[0] != personValue[1])
									&& (personValue[0] != personValue[2])
									&& (personValue[0] != personValue[3])
									&& (personValue[0] != personValue[4])
									&& (personValue[1] != personValue[2])
									&& (personValue[1] != personValue[3])
									&& (personValue[1] != personValue[4])
									&& (personValue[2] != personValue[3])
									&& (personValue[2] != personValue[4])
									&& (personValue[3] != personValue[4])) {
								for (int i = 0; i < person.length; i++) {
									System.out.println(person[i] + "的名次是:"
											+ personValue[i]);
								}
							}
						}
	}
}
 5位跳水高手参加10米高台跳水决赛,有好事者让5人据实力预测比赛结果。
A选手说:B第二,我第三;
B选手说:我第二,E第四;
C选手说:我第一,D第二;
D选手说:C最后,我第三;
E选手说:我第四,A第一。
决赛成绩公布之后,每位选手的预测都只说对了一半,即一对一错.请编程解出比赛的实际名次。
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值