Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- //Input
- //The input data should be read from the console. You will receive an integer number X. Note that X will always be equal to Y and Z will always be (X / 2) + 1. (Refer to the examples).
- //Output
- //The output should be printed on the console.
- //Use the “*” (asterisk) character to print the logo and “.” (dot) for the rest.
- //Constraints
- //• X will always be a positive odd number between 3 and 27 inclusive.
- //• Allowed working time for your program: 0.1 seconds.
- //• Allowed memory: 16 MB.
- //Examples
- //Example
- //input Example
- //output
- //3
- //.*...*.
- //*.*.*.*
- //...*...
- //..*.*..
- //.*...*.
- //..*.*..
- //...*...
- //Example input Example output
- //5
- //..*.......*..
- //.*.*.....*.*.
- //*...*...*...*
- //.....*.*.....
- //......*......
- //.....*.*.....
- //....*...*....
- //...*.....*...
- //..*.......*..
- //...*.....*...
- //....*...*....
- //.....*.*.....
- //......*......
- class Program
- {
- static void Main()
- {
- int x = int.Parse(Console.ReadLine());
- int z = x / 2 + 1;
- int length = 3 * x - 2;
- int height = length;
- int[,] matrix = new int[height, length];
- z = z - 1; // start from zero
- // --> z
- for (int row = z, col = 0; col <= z; col++, row --)
- {
- matrix[row, col] = 1;
- }
- // z <--
- for (int row = z, col = length-1; row >= 0; col--, row--)
- {
- matrix[row, col] = 1;
- }
- // --> 2x-1
- for (int row = 0, col = z; row < x*2-1; col++, row++)
- {
- matrix[row, col] = 1;
- }
- // 2x-1 <--
- for (int row = 0, col = length - z -1; row < x * 2 - 1; col--, row++)
- {
- matrix[row, col] = 1;
- }
- // --> v
- for (int row = x * 2 - 1, col = z + 1; row < length; col++, row++)
- {
- matrix[row, col] = 1;
- }
- // v <--
- for (int row = x * 2 - 1, col = length - z - 2; row < length; col--, row++)
- {
- matrix[row, col] = 1;
- }
- //print
- PrintMatrix(matrix);
- }
- private static void PrintMatrix(int[,] matrix)
- {
- for (int row = 0; row < matrix.GetLength(0); row++)
- {
- for (int col = 0; col < matrix.GetLength(1); col++)
- {
- if (matrix[row, col] == 1)
- {
- Console.Write("*");
- }
- else
- {
- Console.Write(".");
- }
- }
- Console.WriteLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement