sashomaga

Untitled

Jan 4th, 2013
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.06 KB | None | 0 0
  1. using System;
  2.  
  3.  
  4. class Program
  5. {
  6.     static void Main()
  7.     {
  8.         int n = int.Parse(Console.ReadLine());
  9.  
  10.         int count;
  11.         if ((n / 2 & 1) == 1)
  12.         {
  13.             count = n / 4 + 1;
  14.         }
  15.         else
  16.         {
  17.             count = n / 4;
  18.         }
  19.  
  20.         char[,] matrix = new char[n, n];
  21.  
  22.         for (int i = 0; i / 2 < count; i += 2)
  23.         {
  24.             // / up
  25.             for (int x = n / 2 - 1, y = 0 + i; y < n / 2; x--, y++)
  26.             {
  27.                 matrix[x, y] = '/';
  28.             }
  29.             // \ up
  30.             for (int x = n / 2 - 1, y = n - 1 - i; y > n / 2 - 1; x--, y--)
  31.             {
  32.                 matrix[x, y] = '\\';
  33.             }
  34.             // \ down
  35.             for (int x = n / 2, y = 0 + i; y < n / 2; x++, y++)
  36.             {
  37.                 matrix[x, y] = '\\';
  38.             }
  39.             // / down
  40.             for (int x = n / 2, y = n - 1 - i; y > n / 2 - 1; x++, y--)
  41.             {
  42.                 matrix[x, y] = '/';
  43.             }
  44.         }
  45.         // dots
  46.         for (int x = 0; x < n; x++)
  47.         {
  48.             for (int y = 0; y < n; y++)
  49.             {
  50.                 if (matrix[x, y] == 0)
  51.                 {
  52.                     if (x == 0 || y == 0 || y == n - 1)
  53.                     {
  54.                         matrix[x, y] = '.';
  55.                     }
  56.                     else if (matrix[x - 1, y] == '.' || matrix[x, y - 1] == '.')
  57.                     {
  58.                         matrix[x, y] = '.';
  59.                     }
  60.                     else if (matrix[x, y - 1] == '/' && matrix[x, y + 1] == 0 && x > n / 2)
  61.                     {
  62.                         matrix[x, y] = '.';
  63.                     }
  64.                 }
  65.             }
  66.         }
  67.         PrintMatrix(matrix, n);
  68.     }
  69.  
  70.     private static void PrintMatrix(char[,] matrix, int n)
  71.     {
  72.         for (int x = 0; x < n; x++)
  73.         {
  74.             for (int y = 0; y < n; y++)
  75.             {
  76.                 Console.Write(matrix[x,y]);
  77.             }
  78.             Console.WriteLine();
  79.         }
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment