Star Pattern 18
Time limit1sMemory limit256 MB
Print the size N star figure of nested triangles with alternating orientation defined recursively.
- Level
Medium4 of 10
- Topics
- Recursion, Matrix, Implementation
- Solved
- No attempts yet
Problem
Print the star figure of size . The figure of size takes up lines and columns, and every cell without a star is a space.
The figure of size 1 is a single star.
When and is odd, the figure is a triangle pointing up. Put a star in the middle column of the first line, then draw the two slanted sides from that cell. Going down one line at a time, the left side moves one column to the left and the right side moves one column to the right. The last line is all stars, from the leftmost column to the rightmost column. Then draw the figure of size as well, horizontally centered, on the lines directly above the last line.
When is even, the figure is the same shape turned upside down. The first line is all stars, and the two slanted sides move one column inward per line until they meet in the middle column of the last line. The figure of size is horizontally centered on the lines directly below the first line.
The two slanted sides and the inner figure occupy different cells, so they never overlap.
Input
The first line contains ().
Output
Print the figure of size line by line, starting from the first line. Do not print the spaces that follow the last star on a line.