Advertisement
VladoG

[PB] - Drawing with Loops - 10. Diamond

Feb 18th, 2017
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.82 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 _10_Diamond
  8.     {
  9.     class Program
  10.         {
  11.         static void Main(string[] args)
  12.             {
  13.             int n = int.Parse(Console.ReadLine());
  14.             var leftRight = (n - 1) / 2;
  15.  
  16.             if (n == 1)
  17.                 {
  18.                 Console.WriteLine('*');
  19.                 }
  20.             else
  21.                 {
  22.                 for (int i = 1; i <= (n - 1) / 2; i++)
  23.                     {
  24.                     // Draw the TOP part
  25.                     Console.Write(new string('-', leftRight));
  26.                     Console.Write("*");
  27.                     var mid = n - 2 * leftRight - 2;
  28.                     if (mid >= 0)
  29.                         {
  30.                         Console.Write(new string('-', mid));
  31.                         Console.Write("*");
  32.                         }
  33.                     Console.WriteLine(new string('-', leftRight));
  34.                     leftRight--;
  35.                     }
  36.  
  37.                 // MIDDLE ROW
  38.                 Console.WriteLine('*' + new string('-', n - 2) + '*');
  39.  
  40.                 // Draw the bottom part
  41.                 leftRight++;
  42.                 for (int i = 1; i <= (n - 1) / 2; i++)
  43.                     {
  44.                     Console.Write(new string('-', leftRight));
  45.                     Console.Write("*");
  46.                     var mid = n - 2 * leftRight - 2;
  47.                     if (mid >= 0)
  48.                         {
  49.                         Console.Write(new string('-', mid));
  50.                         Console.Write("*");
  51.                         }
  52.                     Console.WriteLine(new string('-', leftRight));
  53.                     leftRight++;
  54.                     }
  55.                 }
  56.             }
  57.         }
  58.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement