Advertisement
Ludmil

C# Carpets

Apr 1st, 2014
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.53 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3.  
  4. class Program
  5. {
  6.     static void Main()
  7.     {
  8.         int n = 12;
  9.         int midl = n / 2;
  10.         StringBuilder lineLeft = new StringBuilder();
  11.         StringBuilder lineRight = new StringBuilder();
  12.         for (int i = 0; i < midl; i++)
  13.         {
  14.             if (i % 2 == 0)
  15.             {//tish condition mark shen to ad space or slashes padding fil out the rest
  16.                 lineLeft.Append("/"); lineRight.Insert(0, '\\');
  17.                 Console.WriteLine(lineLeft.ToString().PadLeft((midl), '.') + lineRight.ToString().PadRight((midl), '.'));
  18.             }
  19.             else if (i % 2 == 1)
  20.             {
  21.                 lineLeft.Append(" "); lineRight.Insert(0, ' ');
  22.                 Console.WriteLine(lineLeft.ToString().PadLeft((midl), '.') + lineRight.ToString().PadRight((midl), '.'));
  23.             }
  24.         }
  25.         // change slashes direction
  26.         lineLeft.Replace('/', '\\'); lineRight.Replace('\\', '/');
  27.         Console.WriteLine(lineLeft.ToString().PadLeft((midl), '.') + lineRight.ToString().PadRight((midl), '.'));
  28.  
  29.         for (int i = 0; i < midl-1; i++)
  30.         { // just remove inner element from the carpet padding fill up the rest wit dots. to lineLeft inner element is the last one
  31.             // for lineRightinner element is the first - zero element.
  32.             lineLeft.Remove(lineLeft.Length - 1, 1); lineRight.Remove(0, 1);
  33.             Console.WriteLine(lineLeft.ToString().PadLeft((midl), '.') + lineRight.ToString().PadRight((midl), '.'));
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement