编程之美——象棋将帅问题
2015-05-13 11:30
183 查看
解法一:
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);
}
}
相关文章推荐
- )《编程之美》读书笔记(一):中国象棋将帅问题
- 读《编程之美》有感—中国象棋将帅问题
- 编程之美——1.2中国象棋将帅问题
- 编程之美-中国象棋将帅问题
- 编程之美——象棋将帅问题
- 《编程之美》 1.2 中国象棋将帅问题
- 《编程之美》读书笔记(一):中国象棋将帅问题
- (1.5.1.2)编程之美:中国象棋将帅问题——一个变量实现多重循环
- 编程之美1.2中国象棋将帅问题——转载+自己的一点理解
- 《编程之美》读书笔记(1)--中国象棋将帅问题
- 《编程之美》——中国象棋将帅问题
- 《编程之美》中国象棋将帅问题
- 编程之美:中国象棋将帅问题
- 《编程之美》之读书笔记 1.2中国象棋将帅问题
- 《编程之美》学而思-中国象棋将帅问题
- 读书笔记--《编程之美》--中国象棋将帅问题
- 《编程之美》——中国象棋将帅问题
- 《编程之美》读书笔记(一):中国象棋将帅问题
- 《编程之美》1.2 中国象棋将帅问题 学习笔记
- 《编程之美》读书笔记01: 1.2中国象棋将帅问题