题解 | #二维数组操作#

二维数组操作

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();
            int r1 = (m >= 0 && m <= 9) && (n >= 0 && n <= 9) ? 0 : -1;
            int x1 = in.nextInt();
            int y1 = in.nextInt();
            int x2 = in.nextInt();
            int y2 = in.nextInt();
            int r2 = (x1 >= 0 && x1 <= m - 1)
                     && (x2 >= 0 && x2 <= m - 1)
                     && (y1 >= 0 && y1 <= n - 1)
                     && (y2 >= 0 && y2 <= n - 1) ? 0 : -1;
            int row = in.nextInt();
            int r3 = (m >= 0 && m < 9) && (row >= 0 && row <= m - 1) ? 0 : -1;
            int col = in.nextInt();
            int r4 = (n >= 0 && n < 9) && (col >= 0 && col <= n - 1) ? 0 : -1;
            int x = in.nextInt();
            int y = in.nextInt();
            int r5 = (x >= 0 && x <= m - 1) && (y >= 0 && y <= n - 1) ? 0 : -1;
            System.out.println(r1 + "\n" + r2 + "\n" + r3 + "\n" + r4 + "\n" + r5);
        }
    }
}

全部评论

相关推荐

09-12 14:05
不想做程序员:招黑奴呢,我实习都6k,正式没1w我就不做程序员了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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