TopcoderArchiveVisit Topcoder
SRM26 Sep 2007
SRM 367

WhiteCells

Problem statement, definition, constraints, and public examples.

Problem Statement

A chessboard is an 8 x 8 grid of cells. Within each column and within each row, cells alternate between black and white. The cell in the upper left corner (0, 0) is white. You are given a String[] board, where the j-th character of the i-th element is 'F' if the cell in the j-th column from the left and i-th row from the top is occupied, or '.' if it is empty. Return the number of occupied white cells on the board.

Definition

Class:
WhiteCells
Method:
countOccupied
Parameters:
String[]
Returns:
int
Method signature:
int countOccupied(String[] board)
(be sure your method is public)

Constraints

  • board will contain exactly 8 elements.
  • Each element of board will contain exactly 8 characters.
  • board will contain only the characters '.' and 'F'.

Examples

  1. {"........",
     "........",
     "........",
     "........",
     "........",
     "........",
     "........",
     "........"}
    Returns: 0
  2. {"FFFFFFFF",
     "FFFFFFFF",
     "FFFFFFFF",
     "FFFFFFFF",
     "FFFFFFFF",
     "FFFFFFFF",
     "FFFFFFFF",
     "FFFFFFFF"}
    Returns: 32
  3. {".F.F...F",
     "F...F.F.",
     "...F.F.F",
     "F.F...F.",
     ".F...F..",
     "F...F.F.",
     ".F.F.F.F",
     "..FF..F."}
    Returns: 1
  4. {"........",
     "..F.....",
     ".....F..",
     ".....F..",
     "........",
     "........",
     ".......F",
     ".F......"}
    Returns: 2
Back to all problems