题解 | #二维数组操作#

二维数组操作

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 m = in.nextInt();
            int n = in.nextInt();
            if(m>9||n>9){
                System.out.println(-1);
            }else{
                System.out.println(0);
            }
            //交换坐标值
            int x1=in.nextInt();
            int y1=in.nextInt();
            int x2=in.nextInt();
            int y2=in.nextInt();
            if(x1>=m||x2>=m||y1>=n||y2>=n){
                System.out.println(-1);
            }else{
                System.out.println(0);
            }
            //插入
            int x=in.nextInt();
            if(m+1>9||x>=m){
                System.out.println(-1);
            }else{
                System.out.println(0);
            }
            int y=in.nextInt();
            if(n+1>9||y>=n){
                System.out.println(-1);
            }else{
                System.out.println(0);
            }
            //查询
            int ox=in.nextInt();
            int oy=in.nextInt();
            if(ox>=m||oy>=n){
                System.out.println(-1);
            }else{
                System.out.println(0);
            }
        }
    }
}

全部评论

相关推荐

04-21 11:22
已编辑
中华女子学院 UE4
耐心学习_佩可officical:直接举报他,佬,违反劳动法我记得boss会下架
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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