grach

Diamond

Jul 19th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.71 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 Diamond
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int n = int.Parse(Console.ReadLine());
  14.  
  15.             var leftRight = (n - 1) / 2;
  16.             for (int i = 1; i <= (n - 1) / 2; i++)
  17.             { // Draw the top part
  18.                 Console.Write(new string('-', leftRight));
  19.                 Console.Write("*");
  20.                 var mid = n - 2 * leftRight - 2;
  21.                 if (mid >= 0)
  22.                 {
  23.                     Console.Write(new string('-', mid));
  24.                     Console.Write("*");
  25.                 }
  26.                 Console.WriteLine(new string('-', leftRight));
  27.                 leftRight--;
  28.             } // TODO: Draw the bottom part
  29.         }
  30.     }
  31. }*/
  32.  
  33. using System;
  34. using System.Collections.Generic;
  35. using System.Linq;
  36. using System.Text;
  37. using System.Threading.Tasks;
  38.  
  39. namespace _Diamond
  40. {
  41.     class Diamond
  42.     {
  43.         static void Main(string[] args)
  44.         {
  45.             int n = int.Parse(Console.ReadLine());
  46.  
  47.             int stars;
  48.             if (n % 2 == 0)
  49.                 stars = 2;
  50.             else
  51.                 stars = 1;
  52.  
  53.             if (n > 2)
  54.             {
  55.                 Console.WriteLine("{0}{1}{0}", new string('-', (n - stars) / 2), new string('*', stars));
  56.                 int dashes = ((n - stars) / 2) - 1;
  57.  
  58.                 for (int i = 0; i < (n - 3) / 2; i++)
  59.                 {
  60.                     Console.WriteLine("{0}*{1}*{0}", new string('-', dashes), new string('-', stars + (2 * i)));
  61.                     dashes--;
  62.                 }
  63.                 Console.WriteLine("*{0}*", new string('-', n - 2));
  64.  
  65.                 for (int i = ((n - 3) / 2) - 1; i >= 0; i--)
  66.                 {
  67.                     dashes++;
  68.                     Console.WriteLine("{0}*{1}*{0}", new string('-', dashes), new string('-', stars + (2 * i)));
  69.                 }
  70.                 Console.WriteLine("{0}{1}{0}", new string('-', (n - stars) / 2), new string('*', stars));
  71.  
  72.             }
  73.             else
  74.                 Console.WriteLine(new string('*', stars));
  75.         }
  76.     }
  77. }
  78.  
  79.  
  80. /* for (int row = 0; row < n; row++)
  81.  {
  82.  
  83.      Console.Write(new string('-', n - row - 1));
  84.      for (int col = 0; col <= row; col++)
  85.      {
  86.          Console.Write('*');
  87.          Console.Write('-');
  88.  
  89.      }
  90.      Console.WriteLine();
  91.  }
  92.  for (int row = n - 1; row > 0; row--)
  93.  {
  94.      Console.Write(new string('-', n - row));
  95.      for (int col = 0; col < row; col++)
  96.      {
  97.          Console.Write('*');
  98.          Console.Write('-');
  99.      }
  100.      Console.WriteLine();
  101.  }
  102.  
  103. }
  104.  
  105. }
  106. }*/
Advertisement
Add Comment
Please, Sign In to add comment