View difference between Paste ID: EBAwzVeH and CuQY3X2R
SHOW: | | - or go back to the newest paste.
1
using System;
2
3
//The input data should be read from the console.
4
//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.
5
//The input data will always be valid and in the format described. There is no need to check it explicitly.
6
//Output
7
//The output should be printed on the console.
8
//Use the “/” and “\” characters to print the rhomb sides and “.” (dot) for the rest. You should print exactly one space between each rhomb.
9
//Constraints
10
//•	N will always be a positive even number between 6 and 80 inclusive.
11
//•	Allowed working time for your program: 0.1 seconds.
12
//•	Allowed memory: 16 MB.
13
14
//Examples
15
//Example
16
//input	Example
17
//output
18
//6
19
//../\..
20
//./  \.
21
/// /\ \
22
//\ \/ /
23
//.\  /.
24
//..\/..
25
26
//Example input	Example output
27
//12	
28
//...../\.....
29
//..../  \....
30
//.../ /\ \...
31
//../ /  \ \..
32
//./ / /\ \ \.
33
/// / /  \ \ \
34
//\ \ \  / / /
35
//.\ \ \/ / /.
36
//..\ \  / /..
37
//...\ \/ /...
38
//....\  /....
39
//.....\/.....
40
41
class Program
42
{
43
    static void Main()
44
    {
45
        int n = int.Parse(Console.ReadLine());
46
47-
        int count;
47+
        int count; // count of rhombs
48
        if ((n / 2 & 1) == 1)
49
        {
50
            count = n / 4 + 1;
51
        }
52
        else
53
        {
54
            count = n / 4;
55
        }
56
57-
        char[,] matrix = new char[n, n];
57+
        char[,] matrix = new char[n/2, n]; //half matrix
58
        //draw rhomns
59
        for (int i = 0; i / 2 < count; i += 2)
60
        {
61
            // / up
62
            for (int x = n / 2 - 1, y = 0 + i; y < n / 2; x--, y++)
63
            {
64
                matrix[x, y] = '/';
65
            }
66
            // \ up
67
            for (int x = n / 2 - 1, y = n - 1 - i; y > n / 2 - 1; x--, y--)
68
            {
69
                matrix[x, y] = '\\';
70
            }
71-
            // \ down
71+
72-
            for (int x = n / 2, y = 0 + i; y < n / 2; x++, y++)
72+
        // fill dots
73
        for (int x = 0; x < n/2; x++)
74
        {
75
            for (int y = 0; y < n; y++)
76-
            // / down
76+
77-
            for (int x = n / 2, y = n - 1 - i; y > n / 2 - 1; x++, y--)
77+
78
                {
79
                    if (x == 0)
80
                    {
81
                        matrix[x, y] = '.';
82-
        // dots
82+
83-
        for (int x = 0; x < n; x++)
83+
                    else if (matrix[x - 1, y] == '.')
84
                    {
85
                        matrix[x, y] = '.';
86
                    }
87
                }
88
            }
89-
                    if (x == 0 || y == 0 || y == n - 1)
89+
90
        PrintMatrix(matrix, n);
91
        PrintReversedMatrix(matrix, n);
92
    }
93-
                    else if (matrix[x - 1, y] == '.' || matrix[x, y - 1] == '.')
93+
94
    private static void PrintReversedMatrix(char[,] matrix, int n)
95
    {
96
        for (int x = n/2-1; x >=0; x--)
97-
                    else if (matrix[x, y - 1] == '/' && matrix[x, y + 1] == 0 && x > n / 2)
97+
98
            for (int y = 0; y < n; y++)
99
            {
100
               
101
                if (matrix[x, y] == '\\') 
102
                {
103
                    Console.Write("/");
104
                }
105
                else if (matrix[x, y] == '/')
106
                {
107
                    Console.Write("\\");
108
                }
109-
        for (int x = 0; x < n; x++)
109+
                else
110
                {
111
                    Console.Write(matrix[x, y]);
112
                }
113-
                if (matrix[x, y] == 0) 
113+
114
            Console.WriteLine();
115-
                    matrix[x, y] = ' ';
115+
116
    }
117-
                Console.Write(matrix[x,y]);
117+
118
    private static void PrintMatrix(char[,] matrix, int n)
119
    {
120
        for (int x = 0; x < n/2; x++)
121
        {
122
            for (int y = 0; y < n; y++)
123
            {
124
                if (matrix[x, y] == 0)
125
                {
126
                    matrix[x, y] = ' '; //fill empty elements of array
127
                }
128
                Console.Write(matrix[x, y]);
129
            }
130
            Console.WriteLine();
131
        }
132
    }
133
}