Advertisement
fbinnzhivko

03.01 Sunglasses

Apr 27th, 2016
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 KB | None | 0 0
  1. using System;
  2. class Sunglasses
  3. {
  4.     static void Main()
  5.     {
  6.         int n = int.Parse(Console.ReadLine()); // Sunglasses height        
  7.  
  8.         for (int i = 0; i < n; i++)
  9.         {
  10.             if (i == 0 || i == n - 1)
  11.             {
  12.                 PrintTopBottomPart(n);
  13.             }
  14.             else
  15.             {
  16.                 PrintMiddlePart(n, i);
  17.             }
  18.         }
  19.     }
  20.     private static void PrintMiddlePart(int n, int i)
  21.     {
  22.         string lens = new string('/', n * 2 - 2);
  23.         string middleFrame = string.Format("{0}{1}{0}", '*', lens);
  24.         string connection = new string(' ', n); // Default empty space between the two frames
  25.         // Checking if the row we're currently at is the one that the bridge should be on
  26.         if (i == n / 2)
  27.         {
  28.             connection = new string('|', n); // Bridge
  29.         }
  30.         Console.WriteLine("{0}{1}{0}", middleFrame, connection);
  31.     }
  32.  
  33.     private static void PrintTopBottomPart(int n)
  34.     {
  35.         string frame = new string('*', 2 * n);
  36.         string emptySpace = new string(' ', n);
  37.         Console.WriteLine("{0}{1}{0}", frame, emptySpace);
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement