题解 | #二维数组操作#

二维数组操作

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

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int r, c, r1, c1, r2, c2, ri, ci, rt, ct;
        while (sc.hasNext()) {
            r = sc.nextInt();
            c = sc.nextInt();
            r1 = sc.nextInt();
            c1 = sc.nextInt();
            r2 = sc.nextInt();
            c2 = sc.nextInt();
            ri = sc.nextInt();
            ci = sc.nextInt();
            rt = sc.nextInt();
            ct = sc.nextInt();
            //1. 数据表的最大规格为9行*9列。
            if (r <= 9 && c <= 9) {
                System.out.println(0);
            } else {
                System.out.println(-1);
            }

            //2. 交换坐标必须在合理区间内
            if ((r1 < r && r2 < r) && (c1 < c && c2 < c)) {
                System.out.println(0);
            } else {
                System.out.println(-1);
            }

            //插入行和列的时候,要注意,只有在原来的行和列是小于9的情况下才能插入
            //对于插入操作,如果插入后行数或列数超过9了则应返回错误。如果插入成功了则将数据表恢复至初始化的 m*n 大小,多出的数据则应舍弃。
            if (ri < r && r < 9) {
                System.out.println(0);
            } else {
                System.out.println(-1);
            }

            if (ci < c && c < 9) {
                System.out.println(0);
            } else {
                System.out.println(-1);
            }
            
            //无论怎么插入行和列, 表格永远是初始的规格大小
            if (rt < r && ct < c) {
                System.out.println(0);
            } else {
                System.out.println(-1);
            }
        }
        sc.close();
    }
}

全部评论

相关推荐

03-03 23:12
已编辑
北京邮电大学 Java
书海为家:我来给一点点小建议,因为毕竟还在学校不像工作几年的老鸟有丰富的项目经验,面试官在面试在校生的时候更关注咱们同学的做事逻辑和思路,所以最好在简历中描述下自己做过项目的完整过程,比如需求怎么来的,你对需求的解读,你想到的解决办法,遇到困难如何找人求助,最终项目做成了什么程度,你从中收获了哪些技能,你有什么感悟。
你的简历改到第几版了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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