TopcoderArchiveVisit Topcoder
SRM25 Aug 2014
SRM 633

Target

Problem statement, definition, constraints, and public examples.

Problem Statement

Here at [topcoder], we call a contestant a "target" if their rating is 3000 or more. In the arena, the targets have a red icon with a small target on it. Do you want to become a target as well? Sure you do. But before you get there, let's start with something easier: drawing a target.


The target you need to draw consists of nested squares. The innermost square is just a single '#' character. The larger squares use alternatingly the character ' ' (space) and the character '#'. Here is an example in which the side of the largest square is n = 5:


#####
#   #
# # #
#   #
#####


And here is an example for n = 9:

#########
#       #
# ##### #
# #   # #
# # # # #
# #   # #
# ##### #
#       #
#########



You will be given an int n. Your method must return a String[] which contains a drawing of the target with side n. More precisely, each element of the returned String[] must be one row of the drawing, in order. Therefore, the returned String[] will consist of n elements, each with n characters. (See the examples below for clarification.)


The value of n will be such that a target like the ones above can be drawn: 5, 9, 13, and so on. Formally, n will be of the form 4k+1, where k is a positive integer.

Definition

Class:
Target
Method:
draw
Parameters:
int
Returns:
String[]
Method signature:
String[] draw(int n)
(be sure your method is public)

Constraints

  • n will be between 5 and 49, inclusive.
  • n mod 4 will be 1.

Examples

  1. 5
    Returns: {"#####", "#   #", "# # #", "#   #", "#####" }
  2. 9
    Returns: {"#########", "#       #", "# ##### #", "# #   # #", "# # # # #", "# #   # #", "# ##### #", "#       #", "#########" }
  3. 13
    Returns: {"#############", "#           #", "# ######### #", "# #       # #", "# # ##### # #", "# # #   # # #", "# # # # # # #", "# # #   # # #", "# # ##### # #", "# #       # #", "# ######### #", "#           #", "#############" }
  4. 17
    Returns: {"#################", "#               #", "# ############# #", "# #           # #", "# # ######### # #", "# # #       # # #", "# # # ##### # # #", "# # # #   # # # #", "# # # # # # # # #", "# # # #   # # # #", "# # # ##### # # #", "# # #       # # #", "# # ######### # #", "# #           # #", "# ############# #", "#               #", "#################" }
Back to all problems