simonradev

Diamond

Aug 10th, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.13 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 LiveDemo
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int size = int.Parse(Console.ReadLine());
  14.            
  15.             char asterisk = '*';
  16.             char whiteSpace = ' ';
  17.             char forwardSlash = '/';
  18.             char pipe = '|';
  19.             char dash = '-';
  20.  
  21.             int countOfAsterisk = 1;
  22.             if (size % 2 == 0)
  23.             {
  24.                 countOfAsterisk = 2;
  25.             }
  26.  
  27.             int countOfDashes = (size - countOfAsterisk) / 2;
  28.  
  29.             string topAndBotRow = string.Format("{0}{1}{0}", new string(dash, countOfDashes),
  30.                                                              new string(asterisk, countOfAsterisk));
  31.  
  32.             Console.WriteLine(topAndBotRow);
  33.  
  34.             int totalRows = size;
  35.             if (size % 2 == 0)
  36.             {
  37.                 size--;
  38.             }
  39.            
  40.             int rowsOfTopPart = (totalRows - 1) / 2;
  41.             int countOfMiddleDashes = countOfAsterisk;
  42.             for (int currentRow = 0; currentRow < rowsOfTopPart; currentRow++)
  43.             {
  44.                 countOfDashes--;
  45.                 string sideDashes = new string(dash, countOfDashes);
  46.                 string middleDashes = new string(dash, countOfMiddleDashes);
  47.                 countOfMiddleDashes += 2;
  48.  
  49.                 Console.WriteLine("{0}*{1}*{0}", sideDashes, middleDashes);
  50.             }
  51.  
  52.             int rowsOfBottomPart = rowsOfTopPart - 1;
  53.             countOfMiddleDashes -= 4;
  54.             for (int currentRow = 1; currentRow <= rowsOfBottomPart; currentRow++)
  55.             {
  56.                 string sideDashes = new string(dash, currentRow);
  57.                 string middleDashes = new string(dash, countOfMiddleDashes);
  58.                 countOfMiddleDashes -= 2;
  59.  
  60.                 Console.WriteLine("{0}*{1}*{0}", sideDashes, middleDashes);
  61.             }
  62.  
  63.             if (size > 2)
  64.             {
  65.                 Console.WriteLine(topAndBotRow);
  66.             }
  67.         }
  68.     }
  69. }
Add Comment
Please, Sign In to add comment