题解 | #二维数组操作#

二维数组操作

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.hasNext()){
            int m=in.nextInt(), n=in.nextInt();
            if(m<=9 && n<=9 && m>=0 && n>=0){
                System.out.println(0);
            }
            else{
                System.out.println(-1);
            }
            boolean isWrong = false;
            for(int i=0 ; i<2 ; ++i){
                int x = in.nextInt();
                int y = in.nextInt();
                if(x>=m || y>=n){
                    isWrong=true;
                }
            }
            if(isWrong){
                System.out.println(-1);
            }
            else{
                System.out.println(0);
            }
            int addPos = in.nextInt();
            if(m == 9 || addPos>=m){
                System.out.println(-1);
            }
            else{
                System.out.println(0);
                //m+=1;
            }

            int addy = in.nextInt();
            if(n==9 || addy>=n){
                System.out.println(-1);
            }
            else{
                System.out.println(0);
                //n+=1;
            }

            int x = in.nextInt(), y=in.nextInt();
            if(x<m && x>=0 && y>=0 && y<n){
                System.out.println(0);
            }
            else{
                System.out.println(-1);
            }

        }
    }
}

全部评论

相关推荐

点赞 评论 收藏
分享
大世界中的渺小一棵:看出来你软硬都有基础,但是这样写简历软硬都擦边不知道你想投什么,建议针对岗位jd针对性修改下。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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