TopcoderArchive
Archive
Algorithm problem

OutlineSquares

Problem statement, definition, constraints, and public examples.

Problem Statement

You are given a String[], squares, each element of which contains the side length and coordinates of the upper left corner of a square. Draw all of the squares on a 20 x 20 pixel canvas and return the result as a String[]. The upper left corner of the canvas is (0, 0) and the lower right corner is (19, 19). Character j of element i (both 0-indexed) of the return String[] represents the pixel at (i, j). Each square should be drawn as a black outline - in other words, only the 1 pixel wide border of the square should be drawn and all the inner pixels should be left alone. Black pixels should be represented as uppercase 'X' characters and blank pixels should be represented as '.' characters.

Each element of squares will be formatted as "<side> <r> <c>" (quotes for clarity only), where <side> is the side length of a square, and (<r>, <c>) is the location of the upper left corner of that square. All squares will be contained entirely within the 20 x 20 pixel canvas.

Definition

Class:
OutlineSquares
Method:
draw
Parameters:
String[]
Returns:
String[]
Method signature:
String[] draw(String[] squares)
(be sure your method is public)

Constraints

  • squares will contain between 1 and 50 elements, inclusive.
  • Each element of squares will be formatted as "<side> <r> <c>" (quotes for clarity only).
  • Each <side> will be between an integer between 1 and 20, inclusive, with no leading zeros.
  • Each <r> and each <c> will be an integer between 0 and 19, inclusive, with no leading zeros.
  • Each element of squares will represent a square that will fit entirely on the 20 x 20 canvas.

Examples

  1. {"20 0 0", "10 5 5"}
    Returns: {"XXXXXXXXXXXXXXXXXXXX", "X..................X", "X..................X", "X..................X", "X..................X", "X....XXXXXXXXXX....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....X", "X....XXXXXXXXXX....X", "X..................X", "X..................X", "X..................X", "X..................X", "XXXXXXXXXXXXXXXXXXXX" }
  2. {"10 1 2", "10 5 5", "10 8 9"}
    Returns: {"....................", "..XXXXXXXXXX........", "..X........X........", "..X........X........", "..X........X........", "..X..XXXXXXXXXX.....", "..X..X.....X..X.....", "..X..X.....X..X.....", "..X..X...XXXXXXXXXX.", "..X..X...X.X..X...X.", "..XXXXXXXXXX..X...X.", ".....X...X....X...X.", ".....X...X....X...X.", ".....X...X....X...X.", ".....XXXXXXXXXX...X.", ".........X........X.", ".........X........X.", ".........XXXXXXXXXX.", "....................", "...................." }
  3. {"7 11 8", "1 18 13", "2 3 3", "3 9 0"}
    Returns: {"....................", "....................", "....................", "...XX...............", "...XX...............", "....................", "....................", "....................", "....................", "XXX.................", "X.X.................", "XXX.....XXXXXXX.....", "........X.....X.....", "........X.....X.....", "........X.....X.....", "........X.....X.....", "........X.....X.....", "........XXXXXXX.....", ".............X......", "...................." }
Back to all problems