首页 > 其他 > 详细

编程之美——象棋将帅问题

时间:2015-05-13 18:51:04      阅读:156      评论:0      收藏:0      [点我收藏+]

技术分享

 

解法一:


public class Chess_Test {
    
    public static void main(String[] args) throws InterruptedException{
        long t1 = System.currentTimeMillis();
        
        Byte i = 81;
        while(i-- > 0){
            if(i / 9 % 3 == i % 9 % 3)
                continue;
            System.out.println(String.format("A = %d, B = %d\n", i / 9 + 1, i % 9 + 1));
        }
        System.out.println(System.currentTimeMillis()-t1);
        
    }
}

解法二:




public class Chess_Test2 {
    
    class Point{
        char a;
        char b;
    }
    
    public static void main(String[] args) throws InterruptedException{
        long t1 = System.currentTimeMillis();
        Point p = new Chess_Test2().new Point();
        for(p.a = 1; p.a <= 9; p.a++){
            for(p.b = 1; p.b <= 9; p.b++){
                if(p.a % 3 == p.b % 3){
                    continue;
                }
                System.out.println(String.format("A = %c, B = %c\n", p.a+‘0‘, p.b+‘0‘));
            }
        }
        System.out.println(System.currentTimeMillis()-t1);
        
    }
}

编程之美——象棋将帅问题

原文:http://www.cnblogs.com/edward-tj/p/4501129.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!