class="java" name="code">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第一。 决赛成绩公布之后,每位选手的预测都只说对了一半,即一对一错.请编程解出比赛的实际名次。