poj 1656 大水题

来源:互联网 发布:中远网络 招聘 编辑:程序博客网 时间:2024/03/29 21:56
package com.liang.poj;import java.util.Scanner;public class Test1656 {static int num = 0;static boolean[][] visited = new boolean[101][101]; // white false ; // black true;public static void main(String[] args) throws Exception {Scanner scan = new Scanner(System.in);int n = scan.nextInt();String[] str = new String[n + 1];for (int i = 0; i < str.length; i++) {str[i] = scan.nextLine();}for (int i = 1; i < str.length; i++) {String[] strArray = str[i].split(" ");liang(strArray);}}public static void liang(String[] strArray) {int row = Integer.parseInt(strArray[1]);int col = Integer.parseInt(strArray[2]);int l = Integer.parseInt(strArray[3]);if (strArray[0].equals("BLACK")) {for (int i = row; i < row + l; i++) {for (int j = col; j < col + l; j++) {visited[i][j] = true;}}} else if(strArray[0].equals("WHITE") ) {for (int i = row; i < row + l; i++) {for (int j = col; j < col + l; j++) {visited[i][j] = false;}}} else {for (int i = row; i < row + l; i++) {for (int j = col; j < col + l; j++) {if(visited[i][j]) {num ++ ;}}}System.out.println(num);num = 0;}}}