题解 | 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);
        }


    }

}
}

全部评论

相关推荐

Cassifa:发的字比你都多的一律视为骗子或者想白嫖压榨实习生的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务