题解 | HJ83#二维数组操作#

二维数组操作

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

import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
//    4 9
//    5 1 2 6
//    0
//    8
//    2 3
//    4 7
    Scanner scanner = new Scanner(System.in);
    while (scanner.hasNextInt()){
        int m = scanner.nextInt();//行数m
        int n = scanner.nextInt();//列数n
        int a = scanner.nextInt();//x1
        int b = scanner.nextInt();//y1
        int c = scanner.nextInt();//x2
        int d = scanner.nextInt();//y2
        int e = scanner.nextInt();//输入要插入的行的数值
        int f = scanner.nextInt();//输入要插入的列的数值
        int g = scanner.nextInt();//输入要查询的x
        int h = scanner.nextInt();//输入要查询的y
        //初始化表格
        if (m<=9&&n<=9){
            System.out.println(0);
        }else {
            System.out.println(-1);
        }
        //交换对应坐标的值
        if (a<=m-1&&b<=n-1&&c<=m-1&&d<=n-1){
            System.out.println(0);
        }else {
            System.out.println(-1);
        }

        //插入行
        if (m!=9){
                if (e>=0&&e<=m-1){System.out.println(0);}
                else {
                    System.out.println(-1);
                }
        } else {
            if (e>0){System.out.println(-1);}
            else {
                System.out.println(0);
            }
        }
        //插入列
        if (n!=9){
            if (f>=0&&f<=n-1){System.out.println(0);}
            else {
                System.out.println(-1);
            }
        } else {
            if (f>0){System.out.println(-1);}
            else {
                System.out.println(0);
            }
        }


        //查找
        if (g<=m-1&&h<=n-1){
            System.out.println(0);
        }else {
            System.out.println(-1);
        }


    }

}
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
06-29 17:30
找实习找着找着就要进入7月了,马上秋招也要开始了,找实习还有意义吗?
绝迹的星:有面就面, 没面上就当日薪4位数大佬免费培训, 面上了再考虑要不要实习
点赞 评论 收藏
分享
风中翠竹:真的真的真的没有kpi。。。面试官是没有任何kpi的,捞是真的想试试看这个行不行,碰碰运气,或者是面试官比较闲现在,没事捞个人看看。kpi算HR那边,但是只有你入职了,kpi才作数,面试是没有的。
双非有机会进大厂吗
点赞 评论 收藏
分享
头顶尖尖的程序员:我是26届的不太懂,25届不应该是找的正式工作吗?为什么还在找实习?大四还实习的话是为了能转正的的岗位吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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