Connection Status:
Competition Arena > ChessboardPattern
SRM 333 · 2007-01-04 · by misof · Simple Search, Iteration, String Manipulation
Class Name: ChessboardPattern
Return Type: String[]
Method Name: makeChessboard
Arg Types: (int, int)
Problem Statement

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).

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." }
4)
1
1
Returns: {"." }

Submissions are judged against all 33 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class ChessboardPattern with a public method vector<string> makeChessboard(int rows, int columns) · 33 test cases · 2 s / 256 MB per case

Submitting as anonymous