Advertisement
sashomaga

Carpets

Jan 4th, 2013
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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;
  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];
  58.  
  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
  72.             for (int x = n / 2, y = 0 + i; y < n / 2; x++, y++)
  73.             {
  74.                 matrix[x, y] = '\\';
  75.             }
  76.             // / down
  77.             for (int x = n / 2, y = n - 1 - i; y > n / 2 - 1; x++, y--)
  78.             {
  79.                 matrix[x, y] = '/';
  80.             }
  81.         }
  82.         // dots
  83.         for (int x = 0; x < n; x++)
  84.         {
  85.             for (int y = 0; y < n; y++)
  86.             {
  87.                 if (matrix[x, y] == 0)
  88.                 {
  89.                     if (x == 0 || y == 0 || y == n - 1)
  90.                     {
  91.                         matrix[x, y] = '.';
  92.                     }
  93.                     else if (matrix[x - 1, y] == '.' || matrix[x, y - 1] == '.')
  94.                     {
  95.                         matrix[x, y] = '.';
  96.                     }
  97.                     else if (matrix[x, y - 1] == '/' && matrix[x, y + 1] == 0 && x > n / 2)
  98.                     {
  99.                         matrix[x, y] = '.';
  100.                     }
  101.                 }
  102.             }
  103.         }
  104.         PrintMatrix(matrix, n);
  105.     }
  106.  
  107.     private static void PrintMatrix(char[,] matrix, int n)
  108.     {
  109.         for (int x = 0; x < n; x++)
  110.         {
  111.             for (int y = 0; y < n; y++)
  112.             {
  113.                 if (matrix[x, y] == 0)
  114.                 {
  115.                     matrix[x, y] = ' ';
  116.                 }
  117.                 Console.Write(matrix[x,y]);
  118.             }
  119.             Console.WriteLine();
  120.         }
  121.     }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement