Advertisement
G_Burlakova

Carpets

Mar 11th, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.86 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.  
  8.     class Carpets
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             // For this task the figure is devided into two parts - triangles, with one "for-loop" for each one
  13.             // Each part is an isosceles triangle so each line of of it will be formed from two other strings - left and right,
  14.             //with equal number of chars
  15.             int height = int.Parse(Console.ReadLine());
  16.             int width = height;
  17.             int maxLines = height / 2; //This is the maximal number of lines for each triangle
  18.             int dotsMaxCount = (width - 2) / 2;  
  19.             char charLeft;
  20.             char charRight;
  21.             int charDefinitor = 1;
  22.             string leftSide;
  23.             string rightSide;
  24.             int maxCharsInASide = width / 2;
  25.  
  26.             // Top triangle
  27.             for (int i = 1; i <= maxLines; i++)
  28.             {
  29.                 leftSide = new string('.', dotsMaxCount);
  30.                 rightSide = leftSide;
  31.                 for (int j = dotsMaxCount; j < maxCharsInASide; j++)
  32.                 {
  33.                     if (charDefinitor == 1)
  34.                     {
  35.                         charLeft = '/';
  36.                         charRight = '\u005C';
  37.                         charDefinitor = 0;
  38.                     }
  39.                     else
  40.                     {
  41.                         charLeft = ' ';
  42.                         charRight = ' ';
  43.                         charDefinitor = 1;
  44.                     }
  45.                     leftSide = leftSide + charLeft;
  46.                     rightSide = charRight + rightSide;
  47.                 }
  48.                 dotsMaxCount--;
  49.                 charDefinitor = 1;
  50.                 Console.WriteLine(leftSide + rightSide);
  51.             }
  52.  
  53.             dotsMaxCount = 0;
  54.  
  55.             //Bottom triangle
  56.             for (int i = 1; i <= maxLines; i++)
  57.             {
  58.                 leftSide = new string('.', dotsMaxCount);
  59.                 rightSide = leftSide;
  60.                 for (int j = dotsMaxCount; j < maxCharsInASide; j++)
  61.                 {
  62.                     if (charDefinitor == 1)
  63.                     {
  64.                         charLeft = '\u005C';
  65.                         charRight = '/';
  66.                         charDefinitor = 0;
  67.                     }
  68.                     else
  69.                     {
  70.                         charLeft = ' ';
  71.                         charRight = ' ';
  72.                         charDefinitor = 1;
  73.                     }
  74.                     leftSide = leftSide + charLeft;
  75.                     rightSide = charRight + rightSide;
  76.                 }
  77.                 dotsMaxCount++;
  78.                 charDefinitor = 1;
  79.                 Console.WriteLine(leftSide + rightSide);
  80.             }
  81.         }
  82.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement