archangelmihail

SandGlass

Dec 4th, 2013
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.49 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. namespace SandGlass
  8. {
  9.     class SandGlass
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int size = int.Parse(Console.ReadLine());
  14.             int[,] matrix = new int[size, size];
  15.             matrix[size / 2+1, size / 2+1] = 1;
  16.             int start = 0;
  17.             int end = size / 2 + 1;
  18.             for (int row = 0; row < size / 2+1; row++)
  19.             {
  20.                 for (int col = 0; col < size / 2+1; col++)
  21.                 {
  22.                     if (start <= col && col <= end)
  23.                     {
  24.                         matrix[row, col] = 1;
  25.                         matrix[row, size - 1 - col] = 1;
  26.                         matrix[size - 1 - row, col] = 1;
  27.                         matrix[size - 1 - row, size - 1 - col] = 1;
  28.                        
  29.                     }
  30.                 }
  31.                 start++;
  32.             }
  33.  
  34.             for (int row = 0; row < size; row++)
  35.             {
  36.                 for (int col = 0; col < size; col++)
  37.                 {
  38.                     if (matrix[row, col] == 0)
  39.                     {
  40.                         Console.Write('.');
  41.                     }
  42.                     else if (matrix[row, col] == 1)
  43.                     {
  44.                         Console.Write('*');
  45.                     }
  46.                 }
  47.                 Console.WriteLine();
  48.             }
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment