Advertisement
Venciity

[SoftUni C# exam preparation] 04.TelerikLogo MATRIX

Apr 10th, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.81 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. class TelerikLogo
  8. {
  9.     static void Main()
  10.     {
  11.         //initialization
  12.         int x = Int32.Parse(Console.ReadLine());
  13.         int y = x;
  14.         int z = (x / 2) + 1;
  15.  
  16.         int width = (2 * x + 2 * z) - 3; // -3 защото се x и z се застъпват на 3 места ( ъглите )
  17.         int height = width;
  18.  
  19.         int[,] matrix = new int[height, width];
  20.  
  21.         // solution - filling the path with ones (1)
  22.  
  23.         int currentRow = x / 2;
  24.         int currentCol = 0;
  25.  
  26.         while (true)
  27.         {
  28.             matrix[currentRow, currentCol] = 1;
  29.  
  30.             currentRow--;
  31.             currentCol++;
  32.  
  33.             if (currentRow < 0)
  34.             {
  35.                 currentRow++;
  36.                 currentCol--;
  37.                 break;
  38.             }
  39.         }
  40.  
  41.         while (true)
  42.         {
  43.             matrix[currentRow, currentCol] = 1;
  44.  
  45.             currentRow++;
  46.             currentCol++;
  47.  
  48.             if (currentRow == 2 * x - 1 )
  49.             {
  50.                 currentRow--;
  51.                 currentCol--;
  52.                 break;
  53.             }
  54.         }
  55.  
  56.         while (true)
  57.         {
  58.             matrix[currentRow, currentCol] = 1;
  59.  
  60.             currentRow++;
  61.             currentCol--;
  62.  
  63.             if (currentRow == width)
  64.             {
  65.                 currentRow--;
  66.                 currentCol++;
  67.                 break;
  68.             }
  69.         }
  70.  
  71.         while (true)
  72.         {
  73.             matrix[currentRow, currentCol] = 1;
  74.  
  75.             currentRow--;
  76.             currentCol--;
  77.  
  78.             if (currentCol == x / 2 - 1)
  79.             {
  80.                 currentRow++;
  81.                 currentCol++;
  82.                 break;
  83.             }
  84.         }
  85.  
  86.         while (true)
  87.         {
  88.             matrix[currentRow, currentCol] = 1;
  89.  
  90.             currentRow--;
  91.             currentCol++;
  92.  
  93.             if (currentRow < 0)
  94.             {
  95.                 currentRow++;
  96.                 currentCol--;
  97.                 break;
  98.             }
  99.         }
  100.  
  101.         while (true)
  102.         {
  103.             matrix[currentRow, currentCol] = 1;
  104.  
  105.             currentRow++;
  106.             currentCol++;
  107.  
  108.             if (currentCol == width)
  109.             {
  110.                 break;
  111.             }
  112.         }
  113.  
  114.         //printing
  115.         for (int row = 0; row < width; row++)
  116.         {
  117.             for (int col = 0; col < width; col++)
  118.             {
  119.                 if (matrix[row, col] == 0)
  120.                 {
  121.                     Console.Write('.');
  122.                 }
  123.                 else if (matrix[row, col] == 1)
  124.                 {
  125.                     Console.Write('*');
  126.                 }
  127.             }
  128.  
  129.             Console.WriteLine();
  130.         }
  131.     }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement