Target Practice
InterviewTime limit1sMemory limit128 MB
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 , with an X drawn across the middle. Its characters are as follows.
- The first and last rows are a border: one
|, then dash (minus sign)-characters, then one|. - Each of the middle rows is one
|, then inner characters, then one|. - In the inner grid, index the rows and columns from . A cell holds
*if it lies on either diagonal (row == col, or row + col == ), and a space otherwise. This forms the X.
The following is a target of size .
|-----|
|* *|
| * * |
| * |
| * * |
|* *|
|-----|
Input
A single odd integer greater than .
Output
The target of the appropriate size.