This page is still under construction.

Parts of this page are still being built. What you see may change.

Target Practice

Interview

Time limit1sMemory limit128 MB

Summary
Print an n by n square border with an X drawn across the inner grid using asterisks.
Level

Easy2 of 10

Topics
Implementation, Simulation
Solved
No attempts yet

Problem

The Trade Federation is too cheap to buy practice targets for testing the battle droid weapon system. Your job is to write a program that reads an integer specifying the size of a target and prints a target of that size.

A target is a square whose side length is nn, with an X drawn across the middle. Its characters are as follows.

  • The first and last rows are a border: one |, then n−2n-2 dash (minus sign) - characters, then one |.
  • Each of the middle n−2n-2 rows is one |, then n−2n-2 inner characters, then one |.
  • In the inner (n−2)×(n−2)(n-2)\times(n-2) grid, index the rows and columns from 00. A cell holds * if it lies on either diagonal (row == col, or row + col == n−3n-3), and a space otherwise. This forms the X.

The following is a target of size 77.

|-----|
|*   *|
| * * |
|  *  |
| * * |
|*   *|
|-----|

Input

A single odd integer greater than 11.

Output

The target of the appropriate size.

Examples1

  1. Example 1

    Input
    9
    
    Expected output
    |-------|
    |*     *|
    | *   * |
    |  * *  |
    |   *   |
    |  * *  |
    | *   * |
    |*     *|
    |-------|