package Com.gg; import java.util.*; public class Glass { public static void main(String[] args) { int n = 6; int[][] arr = new int[][] { {0, 0, 0, 0, 0, 0}, {0, 0, 1, 1, 1, 1}, {1, 1, 0, 1, 1, 0}, {0, 1, 1, 0, 0, 1}, {0, 1, 0, 0, 0, 1}, {0, 1, 0, 1, 0, 1} }; int[][] res = new int[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (j < n - 4 && arr[i][j + 4] + arr[i][j + 3] + arr[i][j] + arr[i][j + 1] + arr[i][j + 2] == 4) { for (int k = j; k < j + 5; k++) { if (arr[i][k] == 0) { res[i][k] = 1; } } } if (i < n - 4 && arr[i][j] + arr[i + 1][j] + arr[i + 2][j] + arr[i + 3][j] + arr[i + 4][j] == 4) { for (int k = i; k < i + 5; k++) { if (arr[k][j] == 0) { res[k][j] = 1; } } } if (i < n - 5 && j < n - 5 && arr[i][j] + arr[i + 1][j + 1] + arr[i + 2][j + 2] + arr[i + 3][j + 3] + arr[i + 4][j + 4] == 4) { for (int k = 0; k < 4; k++) { if (arr[i + k][j + k] == 0) { res[i + k][j + k] = 1; } } } if (i < n - 5 && j > 3 && arr[i][j] + arr[i + 1][j - 1] + arr[i + 2][j - 2] + arr[i + 3][j - 3] + arr[i + 4][j - 4] == 4) { for (int k = 0; k < 4; k++) { if (arr[i + k][j - k] == 0) { res[i + k][j - k] = 1; } } } } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (res[i][j] == 1) { System.out.println(i + " " + j); } } } } }
点赞 评论

相关推荐

accaacc:2到4k,不是2k到4k,所以年薪是30块
点赞 评论 收藏
分享
牛客网
牛客企业服务