TopCoder problem "ChessboardPattern" used in SRM 333 (Division II Level One)



Problem Statement

    

A chessboard pattern is a pattern that satisfies the following conditions:

  • The pattern has a rectangular shape.
  • The pattern contains only the characters '.' (a dot) and 'X' (an uppercase letter X).
  • No two symbols that are horizontally or vertically adjacent are the same.
  • The symbol in the lower left corner of the pattern is '.' (a dot).

You are given two ints rows and columns. Write a method that computes the chessboard pattern with these dimensions, and returns it in a String[]. The elements of the return value correspond to rows of the pattern. Specifically, the first character of the last element of the return value represents the lower left corner (see example 0).

 

Definition

    
Class:ChessboardPattern
Method:makeChessboard
Parameters:int, int
Returns:String[]
Method signature:String[] makeChessboard(int rows, int columns)
(be sure your method is public)
    
 

Constraints

-rows will be between 1 and 50, inclusive.
-columns will be between 1 and 50, inclusive.
 

Examples

0)
    
8
8
Returns: 
{"X.X.X.X.",
".X.X.X.X",
"X.X.X.X.",
".X.X.X.X",
"X.X.X.X.",
".X.X.X.X",
"X.X.X.X.",
".X.X.X.X" }
A standard chessboard. Note that the last element starts with a dot.
1)
    
1
20
Returns: {".X.X.X.X.X.X.X.X.X.X" }
A single row is a special case of a rectangle.
2)
    
5
1
Returns: {".", "X", ".", "X", "." }
And so is a single column.
3)
    
5
13
Returns: 
{".X.X.X.X.X.X.",
"X.X.X.X.X.X.X",
".X.X.X.X.X.X.",
"X.X.X.X.X.X.X",
".X.X.X.X.X.X." }

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=7259

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10657&pm=7259

Writer:

misof

Testers:

PabloGilberto , brett1479 , Olexiy , Mike Mirzayanov

Problem categories:

Simple Search, Iteration, String Manipulation