Advertisement
dimipan80

Exam 3. The Explorer

Jun 6th, 2014
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.19 KB | None | 0 0
  1. namespace _3.TheExplorer
  2. {
  3.     using System;
  4.  
  5.     public class TheExplorer
  6.     {
  7.         public static void Main(string[] args)
  8.         {
  9.             checked
  10.             {
  11.                 int numN = int.Parse(Console.ReadLine());
  12.                 string hyphenSequenceTopAndBottom = new string('-', numN / 2);
  13.                 string hyphenSequenceOnMiddleRow = new string('-', numN - 2);
  14.  
  15.                 // Print Top row:
  16.                 Console.WriteLine("{0}{1}{0}", hyphenSequenceTopAndBottom, '*');
  17.  
  18.                 // Print rows betweens Top and Bottom rows:
  19.                 for (int row = 1; row < numN - 1; row++)
  20.                 {
  21.                     if (row == numN / 2)
  22.                     {
  23.                         Console.WriteLine("{0}{1}{0}", '*', hyphenSequenceOnMiddleRow);
  24.                     }
  25.                     else
  26.                     {
  27.                         // Calculating lenght of Internal hyphen sequences:
  28.                         int lenghtInternalHyphenSequence;
  29.                         if (row < numN / 2)
  30.                         {
  31.                             lenghtInternalHyphenSequence = (row * 2) - 1;                    
  32.                         }
  33.                         else
  34.                         {
  35.                             lenghtInternalHyphenSequence = ((numN - row - 1) * 2) - 1;
  36.                         }
  37.  
  38.                         // Create Internal hyphen sequence:
  39.                         string internalHyphenSequence = new string('-', lenghtInternalHyphenSequence);
  40.  
  41.                         // Calculating and create External hyphen sequence:
  42.                         int lenghtExternalHyphenSequence = (numN - 2 - lenghtInternalHyphenSequence) / 2;
  43.                         string externalHyphenSequence = new string('-', lenghtExternalHyphenSequence);
  44.  
  45.                         // Print current row:
  46.                         Console.WriteLine("{0}{1}{2}{1}{0}", externalHyphenSequence, '*', internalHyphenSequence);
  47.                     }                  
  48.                 }              
  49.  
  50.                 // Print Bottom row:
  51.                 Console.WriteLine("{0}{1}{0}", hyphenSequenceTopAndBottom, '*');
  52.             }
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement