TA的每日心情 | 开心 2021-3-12 23:18 |
---|
签到天数: 2 天 [LV.1]初来乍到
|
C语言趣味程序百例精解之java实现(57)谁家孩子跑得慢

- import static java.lang.Math.abs;
- public class Test571{
- public static void main(String args[]){
- new Test571().whosChildRunSlow571();
- }
- /*
- * 57.谁家孩子跑得慢
- */
- public void whosChildRunSlow571() {
-
- for (int a = 1; a <= 6; a++)
- for (int b = 1; b <= 6; b++)
- for (int c = 1; c <= 6; c++)
- for (int d = 1; d <= 6; d++)
- for (int e = 1; e < 6; e++)
- for (int f = 1; f <= 6; f++)
- if ((9+a + b== 15)&& (8 + c + d == 15) && (7 + e + f == 15)&&(abs(a - b) != 1)
- &&(abs(c - d) != 1)&&(abs(e - f) != 1) && notEquls(new int[] { a,
- b, c, d, e, f })
-
- ) {
-
- System.out.print("(9 " + a+" " +b+") ");
- System.out.print("(8 " + c+" " +d+") ");
- System.out.print("(7 " + e+" " +f+") ");
- System.out.println();
- }
-
-
- }
- /**
- * 判断是否两两不相等
- */
- public boolean notEquls(int[] a) {
- if (a == null || a.length == 0 || a.length == 1)
- return true;
- for (int i = 0; i < a.length; i++) {
- for (int j = 0; j < a.length; j++) {
- if (a[i] == a[j] && i != j) {
- // System.out.println("a[" + i + "]" + a[i] + " a[" + j +
- // "]"
- // + a[j] + "---");
- return false;
- }
- }
- }
- return true;
- }
- }
- /*
- C:at>java Test571
- (9 2 4) (8 1 6) (7 3 5)
- (9 2 4) (8 1 6) (7 5 3)
- (9 2 4) (8 6 1) (7 3 5)
- (9 2 4) (8 6 1) (7 5 3)
- (9 4 2) (8 1 6) (7 3 5)
- (9 4 2) (8 1 6) (7 5 3)
- (9 4 2) (8 6 1) (7 3 5)
- (9 4 2) (8 6 1) (7 5 3)
-
复制代码 王家的孩子是最后一名。
源码下载:http://file.javaxxz.com/2014/11/21/000505765.zip |
|