Advertisement
sashomaga

Carpets

Jan 5th, 2013
106
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; // 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/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.         }
  72.         // fill dots
  73.         for (int x = 0; x < n/2; x++)
  74.         {
  75.             for (int y = 0; y < n; y++)
  76.             {
  77.                 if (matrix[x, y] == 0)
  78.                 {
  79.                     if (x == 0)
  80.                     {
  81.                         matrix[x, y] = '.';
  82.                     }
  83.                     else if (matrix[x - 1, y] == '.')
  84.                     {
  85.                         matrix[x, y] = '.';
  86.                     }
  87.                 }
  88.             }
  89.         }
  90.         PrintMatrix(matrix, n);
  91.         PrintReversedMatrix(matrix, n);
  92.     }
  93.  
  94.     private static void PrintReversedMatrix(char[,] matrix, int n)
  95.     {
  96.         for (int x = n/2-1; x >=0; x--)
  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.                 else
  110.                 {
  111.                     Console.Write(matrix[x, y]);
  112.                 }
  113.             }
  114.             Console.WriteLine();
  115.         }
  116.     }
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement