Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- //The input data should be read from the console.
- //You have an integer number N (always even number) showing the width and the height of the most outer rhomb. The width and the height will always be equal.
- //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 printed on the console.
- //Use the “/” and “\” characters to print the rhomb sides and “.” (dot) for the rest. You should print exactly one space between each rhomb.
- //Constraints
- //• N will always be a positive even number between 6 and 80 inclusive.
- //• Allowed working time for your program: 0.1 seconds.
- //• Allowed memory: 16 MB.
- //Examples
- //Example
- //input Example
- //output
- //6
- //../\..
- //./ \.
- /// /\ \
- //\ \/ /
- //.\ /.
- //..\/..
- //Example input Example output
- //12
- //...../\.....
- //..../ \....
- //.../ /\ \...
- //../ / \ \..
- //./ / /\ \ \.
- /// / / \ \ \
- //\ \ \ / / /
- //.\ \ \/ / /.
- //..\ \ / /..
- //...\ \/ /...
- //....\ /....
- //.....\/.....
- class Program
- {
- static void Main()
- {
- int n = int.Parse(Console.ReadLine());
- int count;
- if ((n / 2 & 1) == 1)
- {
- count = n / 4 + 1;
- }
- else
- {
- count = n / 4;
- }
- char[,] matrix = new char[n, n];
- for (int i = 0; i / 2 < count; i += 2)
- {
- // / up
- for (int x = n / 2 - 1, y = 0 + i; y < n / 2; x--, y++)
- {
- matrix[x, y] = '/';
- }
- // \ up
- for (int x = n / 2 - 1, y = n - 1 - i; y > n / 2 - 1; x--, y--)
- {
- matrix[x, y] = '\\';
- }
- // \ down
- for (int x = n / 2, y = 0 + i; y < n / 2; x++, y++)
- {
- matrix[x, y] = '\\';
- }
- // / down
- for (int x = n / 2, y = n - 1 - i; y > n / 2 - 1; x++, y--)
- {
- matrix[x, y] = '/';
- }
- }
- // dots
- for (int x = 0; x < n; x++)
- {
- for (int y = 0; y < n; y++)
- {
- if (matrix[x, y] == 0)
- {
- if (x == 0 || y == 0 || y == n - 1)
- {
- matrix[x, y] = '.';
- }
- else if (matrix[x - 1, y] == '.' || matrix[x, y - 1] == '.')
- {
- matrix[x, y] = '.';
- }
- else if (matrix[x, y - 1] == '/' && matrix[x, y + 1] == 0 && x > n / 2)
- {
- matrix[x, y] = '.';
- }
- }
- }
- }
- PrintMatrix(matrix, n);
- }
- private static void PrintMatrix(char[,] matrix, int n)
- {
- for (int x = 0; x < n; x++)
- {
- for (int y = 0; y < n; y++)
- {
- if (matrix[x, y] == 0)
- {
- matrix[x, y] = ' ';
- }
- Console.Write(matrix[x,y]);
- }
- Console.WriteLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement