After Angel’s awesome striped tower, he wants a new one. Actually, he asked his “very well-known local producer” if it was possible to make a lot of plaid towels, but every single one to be of different size and color. It turned out it was possible. There is only one problem – someone should program the machines to change the colors and size.
Your task is to write that program. Well not exactly colors are represented by symbols - one for the background and one for the rhombus. The size is the distance between the top left corner and the top edge of the rhombus. See the examples for more clarity.
Input
The input should be read from the console. It will consist three lines.
- 1st line –> the size
- 2nd –> the background symbol
- 3rd –> the rhombus symbol
The input data will always be valid and in the format described. There is no need to check it explicitly.
Output
The output should be the towel design, based on the input values.
Constraints
- The size will be a valid integer in range [0… 100].
- The symbols will be valid symbols from ASCII table.
- Allowed working time for your program: 0.25 seconds.
- Allowed memory: 16 MB.
Examples
Here's my solution:
using System; class PlaidTowel18October2015 { static void Main() { int n = int.Parse(Console.ReadLine()); char a = char.Parse(Console.ReadLine()); char b = char.Parse(Console.ReadLine()); Console.WriteLine("{0}{1}{2}{1}{0}", new string(a, n), b, new string(a, n * 4 + 1 - (n * 2 + 2)));//1ST PART for (int i = 0; i < n - 1; i++)//2ND PART { Console.WriteLine("{0}{1}{2}{1}{3}{1}{2}{1}{0}", new string(a, ((n - 1) - i)), b, new string(a, 1 + i * 2), new string(a, ((((n * 4) + 1) - ((n * 2) + 2)) - 2) - (2 * i))); } Console.WriteLine("{0}{1}{0}{1}{0}", b, new string(a, n * 4 + 1 - (n * 2 + 2)));//3RD PART for (int i = 0; i < n - 1; i++) { Console.WriteLine("{0}{1}{2}{1}{3}{1}{2}{1}{0}", new string(a, (1 + i)), b, new string(a, ((n * 4 + 1 - (n * 2 + 2)) - 2 - 2 * i)), new string(a, 1 + i * 2));//4TH PART } Console.WriteLine("{0}{1}{2}{1}{0}", new string(a, n), b, new string(a, n * 4 + 1 - (n * 2 + 2)));//5TH PART = 1ST PART for (int i = 0; i < n - 1; i++)//6TH PART = 2ND PART { Console.WriteLine("{0}{1}{2}{1}{3}{1}{2}{1}{0}", new string(a, ((n - 1) - i)), b, new string(a, 1 + i * 2), new string(a, ((((n * 4) + 1) - ((n * 2) + 2)) - 2) - (2 * i))); } Console.WriteLine("{0}{1}{0}{1}{0}", b, new string(a, n * 4 + 1 - (n * 2 + 2)));//7TH PART = 3RD PART for (int i = 0; i < n - 1; i++) { Console.WriteLine("{0}{1}{2}{1}{3}{1}{2}{1}{0}", new string(a, (1 + i)), b, new string(a, ((n * 4 + 1 - (n * 2 + 2)) - 2 - 2 * i)), new string(a, 1 + i * 2));//8TH PART = 4TH PART } Console.WriteLine("{0}{1}{2}{1}{0}", new string(a, n), b, new string(a, n * 4 + 1 - (n * 2 + 2)));//9TH PART = 5TH PART = 1ST PART } }