(1,3) (2,3) (3,3) (4,3)
(1,2) (2,3) (3,4)
(4,1) (3,2) (2,3) (1,4)
第1列 | 第2列 | 第3列 | 第4列 | |
第1行 | ||||
(2,3) | 第2行 | |||
第3行 | ||||
第4行 |
(2,1) (2,2) (2,3) (2,4) {同一行上格子的位置}
(1,3) (2,3) (3,3) (4,3) {同列列上格子的位置}
(1,2) (2,3) (3,4) {左上到右下对角线上的格子的位置}
(4,1) (3,2) (2,3) (1,4) {左下到右上对角线上的格子的位置}
package 蓝桥杯java算法训练;
import java.util.Scanner;
public class _3格子位置 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N,i,j;
N = scanner.nextInt();
i = scanner.nextInt();
j = scanner.nextInt();
//同行
for (int j2 = 1; j2 <= N; j2++) {
for (int k = 1; k <= N; k++) {
if (j2 == i) System.out.print("("+j2+","+k+")");
}
}
System.out.println();
//同列
for (int j2 = 1; j2 <= N; j2++) {
for (int k = 1; k <= N; k++) {
if (k == j) System.out.print("("+j2+","+k+")");
}
}
System.out.println();
//从左上到右下对角线上的格子的位置
for (int j2 = 1; j2 <= N; j2++) {
for (int k = 1; k <= N; k++) {
if ((k-j2) ==(j-i) || (j2-k)==(i-j)) System.out.print("("+j2+","+k+")");
}
}
System.out.println();
//从左下到右上对角线上的格子的位置
for (int j2 = N; j2 >= 1; j2--) {
for (int k = N; k >= 1; k--) {
if ((k+j2) ==(j+i) ) System.out.print("("+j2+","+k+")");
}
}
}
}