bacco

Диамант

Feb 11th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.63 KB | None | 0 0
  1. using System;
  2.  
  3. namespace newPro
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.  
  10.             var n = int.Parse(Console.ReadLine());
  11.  
  12.             if (n == 1)
  13.             {
  14.                 Console.WriteLine("*");
  15.             }
  16.             else if (n == 2)
  17.             {
  18.                 Console.WriteLine("**");
  19.             }
  20.             else
  21.             {
  22.                 int starsCount = 1;
  23.  
  24.                 if (n % 2 == 0)
  25.                 {
  26.                     starsCount = 2;
  27.                 }
  28.  
  29.                 int dashesCount = (n - starsCount) / 2;
  30.  
  31.                 string dashes = new string('-', dashesCount);
  32.                 string stars = new string('*', starsCount);
  33.  
  34.                 Console.WriteLine("{0}{1}{0}", dashes, stars);
  35.  
  36.  
  37.                 for (int outerDashes = dashesCount - 1; outerDashes >= 0; outerDashes--)
  38.                 {
  39.                     dashes = new string('-', outerDashes);
  40.  
  41.                     string inerDashes = new string('-', n - 2 * outerDashes - 2);
  42.  
  43.                     Console.WriteLine($"{dashes}*{inerDashes}*{dashes}");
  44.                 }
  45.  
  46.                 for (int outerDashes = 1; outerDashes < (n - 1) / 2; outerDashes++)
  47.                 {
  48.                     string outer = new string('-', outerDashes);
  49.  
  50.                     string inerDashes = new string('-', n - (2 * outerDashes) - 2);
  51.  
  52.                     Console.WriteLine($"{outer}*{inerDashes}*{outer}");
  53.                 }
  54.  
  55.  
  56.                 dashes = new string('-', dashesCount);
  57.  
  58.                 Console.WriteLine("{0}{1}{0}", dashes, stars);
  59.             }
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment