Venciity

[SoftUni C# exam preparation] Carpets

Apr 9th, 2014
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. class Carpets
  8. {
  9.     static void Main()
  10.     {
  11.         int n = Int32.Parse(Console.ReadLine());
  12.  
  13.         for (int i = 1; i <= n / 2; i++) // i = rows
  14.         {
  15.             string filler = new string('.', n / 2 - i);
  16.             Console.Write(filler);
  17.  
  18.             for (int j = 1; j <= i ; j++) // j = cols
  19.             {
  20.                 if (j % 2 != 0) // if col % 2 != 0 , ако колоната е нечетна
  21.                 {
  22.                     Console.Write("/");
  23.                 }
  24.                 else
  25.                 {
  26.                     Console.Write(" ");
  27.                 }
  28.             }
  29.  
  30.             for (int j = 1; j <= i; j++)
  31.             {
  32.                 if (i % 2 == 0) // if row % 2 == 0 , ако редът е четен ( 2,4,6...)
  33.                 {
  34.                     if (j % 2 != 0) // ако колоната е нечетна ( 1,3,5...)
  35.                     {
  36.                         Console.Write(" ");
  37.                     }
  38.                     else
  39.                     {
  40.                         Console.Write("\\");
  41.                     }
  42.                 }
  43.                 else // ако редът е нечетен ( 1,3,5...)
  44.                 {
  45.                     if (j % 2 != 0) // ако колоната е нечетна ( 1,3,5...)
  46.                     {
  47.                         Console.Write("\\");
  48.                     }
  49.                     else
  50.                     {
  51.                         Console.Write(" ");
  52.                     }
  53.                 }
  54.             }
  55.  
  56.             Console.Write(filler);
  57.             Console.WriteLine();
  58.         }
  59.  
  60.         // second part
  61.         int counter = 0;
  62.  
  63.         for (int i = n / 2; i >= 1; i--) // i = rows
  64.         {
  65.             string filler = new string('.', counter);
  66.             Console.Write(filler);
  67.  
  68.             for (int j = 1; j <= i; j++) // j = cols
  69.             {
  70.                 if (j % 2 != 0) // ако колоната е нечетна
  71.                 {
  72.                     Console.Write("\\");
  73.                 }
  74.                 else
  75.                 {
  76.                     Console.Write(" ");
  77.                 }
  78.             }
  79.  
  80.             for (int j = 1; j <= i; j++)
  81.             {
  82.                 if (i % 2 == 0) // ако редът е четен
  83.                 {
  84.                     if (j % 2 != 0) // ако колоната е нечетна
  85.                     {
  86.                         Console.Write(" ");
  87.                     }
  88.                     else
  89.                     {
  90.                         Console.Write("/");
  91.                     }
  92.                 }
  93.                 else
  94.                 {
  95.                     if (j % 2 == 0) // ако колоната е четна
  96.                     {
  97.                         Console.Write(" ");
  98.                     }
  99.                     else
  100.                     {
  101.                         Console.Write("/");
  102.                     }
  103.                 }
  104.             }
  105.  
  106.             Console.Write(filler);
  107.             Console.WriteLine();
  108.             counter++;
  109.         }
  110.     }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment