题解 | #二维数组操作#

二维数组操作

https://www.nowcoder.com/practice/2f8c17bec47e416897ce4b9aa560b7f4

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int a = in.nextInt();
            int b = in.nextInt();
            int[][] arr = new int[a][b];
            if (a <= 9 && b <= 9) {
                System.out.println(0);
            } else {
                System.out.println(-1);
            }
            int x1 = in.nextInt();
            int y1 = in.nextInt();
            int x2 = in.nextInt();
            int y2 = in.nextInt();
            if (isXY(a, b, x1, y1) && isXY(a, b, x2, y2)) {
                System.out.println(0);
            } else {
                System.out.println(-1);
            }
            int ax = in.nextInt();
            if (a + 1 > 9 || ax >= a) {
                System.out.println(-1);
            } else {
                System.out.println(0);
            }
            int ay = in.nextInt();
            if (b + 1 > 9 || ay >= b) {
                System.out.println(-1);
            } else {
                System.out.println(0);
            }
            int cx = in.nextInt();
            int cy = in.nextInt();
            if (isXY(a, b, cx, cy) ) {
                System.out.println(0);
            } else {
                System.out.println(-1);
            }

        }
    }

    public static boolean isXY(int a, int b, int x, int y) {
        if (x >= a || y >= b) {
            return false;
        }
        return true;
    }
}

就是耐心和细心,没有太多技巧

全部评论

相关推荐

05-14 20:34
门头沟学院 Java
窝补药贝八股:管他们,乱说,反正又不去,直接说680
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务