Advertisement
sashomaga

Telerik logo

Dec 30th, 2012
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.62 KB | None | 0 0
  1. using System;
  2.  
  3. //Input
  4. //The input data should be read from the console. You will receive an integer number X. Note that X will always be equal to Y and Z will always be (X / 2) + 1. (Refer to the examples).
  5. //Output
  6. //The output should be printed on the console.
  7. //Use the “*” (asterisk) character to print the logo and “.” (dot) for the rest.
  8. //Constraints
  9. //•   X will always be a positive odd number between 3 and 27 inclusive.
  10. //•   Allowed working time for your program: 0.1 seconds.
  11. //•   Allowed memory: 16 MB.
  12. //Examples
  13. //Example
  14. //input Example
  15. //output
  16. //3
  17. //.*...*.
  18. //*.*.*.*
  19. //...*...
  20. //..*.*..
  21. //.*...*.
  22. //..*.*..
  23. //...*...
  24. //Example input Example output
  25. //5
  26. //..*.......*..
  27. //.*.*.....*.*.
  28. //*...*...*...*
  29. //.....*.*.....
  30. //......*......
  31. //.....*.*.....
  32. //....*...*....
  33. //...*.....*...
  34. //..*.......*..
  35. //...*.....*...
  36. //....*...*....
  37. //.....*.*.....
  38. //......*......
  39.  
  40. class Program
  41. {
  42.     static void Main()
  43.     {
  44.         int x = int.Parse(Console.ReadLine());
  45.         int z = x / 2 + 1;
  46.         int length = 3 * x - 2;
  47.         int height = length;
  48.  
  49.         int[,] matrix = new int[height, length];
  50.  
  51.         z = z - 1; // start from zero
  52.         // --> z
  53.         for (int row = z, col = 0; col <= z; col++, row --)
  54.         {
  55.             matrix[row, col] = 1;
  56.         }        
  57.         // z <--
  58.         for (int row = z, col = length-1; row >= 0; col--, row--)
  59.         {
  60.             matrix[row, col] = 1;
  61.         }
  62.         // --> 2x-1
  63.         for (int row = 0, col = z; row < x*2-1; col++, row++)
  64.         {
  65.             matrix[row, col] = 1;
  66.         }      
  67.         //  2x-1 <--
  68.         for (int row = 0, col = length - z -1; row < x * 2 - 1; col--, row++)
  69.         {
  70.             matrix[row, col] = 1;
  71.         }
  72.         // --> v
  73.         for (int row = x * 2 - 1, col = z + 1; row < length; col++, row++)
  74.         {
  75.             matrix[row, col] = 1;
  76.         }
  77.         // v <--
  78.         for (int row = x * 2 - 1, col = length - z - 2; row < length; col--, row++)
  79.         {
  80.             matrix[row, col] = 1;
  81.         }    
  82.         //print
  83.         PrintMatrix(matrix);
  84.     }
  85.  
  86.     private static void PrintMatrix(int[,] matrix)
  87.     {
  88.         for (int row = 0; row < matrix.GetLength(0); row++)
  89.         {
  90.             for (int col = 0; col < matrix.GetLength(1); col++)
  91.             {
  92.                 if (matrix[row, col] == 1)
  93.                 {
  94.                     Console.Write("*");
  95.                 }
  96.                 else
  97.                 {
  98.                     Console.Write(".");
  99.                 }
  100.             }
  101.             Console.WriteLine();
  102.         }
  103.     }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement