|
C语言趣味程序百例精解之java实现(54)博士的难题2
程序解答:
public class Test54{
public static void main(String args[]){
whoTellLie54();
}
/**
* 54.又是无聊的谁在说谎
* "1"表示诚实族,“2”表示说谎族,“3”表示两面族,abc是三个站成一排的顺序
*/
public static void whoTellLie54() {
for (int a = 1; a <= 3; a++)
for (int b = 1; b <= 3; b++)
for (int c = 1; c <= 3; c++)
if ((a != b && b != c && a != c)
&& (a == 1 && b == 1 || a == 2 && b != 1 || a == 3)
&& (b == 1 && b == 3 || b == 2 && b != 3 || b == 3)
&& (c == 1 && b == 2 || c == 2 && b != 2 || c == 3)) {
System.out.println("a=" + a);
System.out.println("b=" + b);
System.out.println("c=" + c);
}
}
}
C:\bat>java Test54
a=3
b=2
c=1
中间人是说谎族的,左边的人是两面族的,右边的人是诚实族的。 |
|