TopcoderArchiveVisit Topcoder
SRM7 Dec 2016
SRM 707 by Blizzard

Cross

Problem statement, definition, constraints, and public examples.

Problem Statement

There is a rectangular board that is divided into n rows by m columns of cells. Each cell is either black or white. You are given the description of the board in the String[] board. Each character in board represents one cell. More precisely, the character board[i][j] represents the cell at coordinates (row i, column j). The character '#' represents a black cell, the character '.' is a white cell.

You want to find a cross on this board. A cross is a configuration of 5 black cells placed like this:

 #
###
 #


Formally, there is a cross centered at (x, y) if the following five cells are all black: (x, y), (x+1, y), (x-1, y), (x, y-1), and (x, y+1). Note that other cells adjacent to the cross may also be black, it is still a valid cross.

Return "Exists" if there is at least one cross on the given board. Otherwise, return "Does not exist". Note that the return value is case-sensitive.

Definition

Class:
Cross
Method:
exist
Parameters:
String[]
Returns:
String
Method signature:
String exist(String[] board)
(be sure your method is public)

Constraints

  • n, m will be between 3 and 50, inclusive.
  • board will contain exactly n elements.
  • Each element in board will contain exactly m characters.
  • Each character in board will be either '#' or '.'.

Examples

  1. {".##",
     "###",
     "##."}
    Returns: "Exist"
    There is a cross centered at (1,1).
  2. {".##",
     "###",
     "#.."}
    Returns: "Does not exist"
    This time there is no cross.
  3. {"######",
     "######",
     "######",
     "######",
     "######",
     "######",
     "######"}
    Returns: "Exist"
  4. {".#.#",
     "#.#.",
     ".#.#",
     "#.#."}
    Returns: "Does not exist"
  5. {".#.#",
     "###.",
     ".###",
     "#.#."}
    Returns: "Exist"
Back to all problems