题解 | 二维数组操作
解题思路:太简单,顺着提示写就可以了
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
// 初始化
String[] rcArr = in.nextLine().split(" ");
int row = Integer.parseInt(rcArr[0]);
int col = Integer.parseInt(rcArr[1]);
if (row > 0 && row <= 9 && col > 0 && col <= 9) {
System.out.println(0);
} else {
System.out.println(-1);
}
// 交换
String[] switchArr = in.nextLine().split(" ");
int x1 = Integer.parseInt(switchArr[0]);
int y1 = Integer.parseInt(switchArr[1]);
int x2 = Integer.parseInt(switchArr[2]);
int y2 = Integer.parseInt(switchArr[3]);
if (x1 >= 0 && x1 < row && x2 >= 0 && x2 < row && y1 >= 0 && y1 < col &&
y2 >= 0 && y2 < col ) {
System.out.println(0);
} else {
System.out.println(-1);
}
// 插入
int oldRow = row;
int oldCol = col;
int n1 = Integer.parseInt(in.nextLine());
if (row < 9 && n1 < row) {
System.out.println(0);
} else {
System.out.println(-1);
}
int n2 = Integer.parseInt(in.nextLine());
if (col < 9 && n2 < col) {
System.out.println(0);
} else {
System.out.println(-1);
}
// 查询
String[] queryhArr = in.nextLine().split(" ");
int p1 = Integer.parseInt(queryhArr[0]);
int q1 = Integer.parseInt(queryhArr[1]);
if (p1 >= 0 && p1 < oldRow && q1 >= 0 && q1 < oldCol) {
System.out.println(0);
} else {
System.out.println(-1);
}
}
}
}
美的集团公司福利 722人发布