Advertisement
Filkolev

Carpets

Aug 10th, 2014
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.15 KB | None | 0 0
  1. using System;
  2.  
  3. class Carpets
  4. {
  5.     static void Main()
  6.     {
  7.         int width = int.Parse(Console.ReadLine());
  8.  
  9.         // print top half
  10.         for (int i = 0; i < width / 2; i++)
  11.         {
  12.             // print dots to the left
  13.             Console.Write(new string('.', width / 2 - 1 - i));
  14.  
  15.             // print left part or diamonds
  16.             for (int left = 0; left < i + 1; left++)
  17.             {
  18.                 if (left % 2 == 0)
  19.                 {
  20.                     Console.Write('/');
  21.                 }
  22.                 else
  23.                 {
  24.                     Console.Write(' ');
  25.                 }
  26.             }
  27.  
  28.             // print right part of diamonds
  29.             for (int right = i; right < 2 * i + 1; right++)
  30.             {
  31.                 if (right % 2 == 0)
  32.                 {
  33.                     Console.Write('\\');
  34.                 }
  35.                 else
  36.                 {
  37.                     Console.Write(' ');
  38.                 }
  39.             }
  40.  
  41.             // print dots to the right
  42.             Console.Write(new string('.', width / 2 - 1 - i));
  43.  
  44.             Console.WriteLine();
  45.         }
  46.  
  47.         // print bottom half
  48.         for (int i = 0; i < width / 2; i++)
  49.         {
  50.             // print dots to the left
  51.             Console.Write(new string('.', i));
  52.  
  53.             // print left part or diamonds
  54.             for (int left = 0; left < width / 2 - i; left++)
  55.             {
  56.                 if (left % 2 == 0)
  57.                 {
  58.                     Console.Write('\\');
  59.                 }
  60.                 else
  61.                 {
  62.                     Console.Write(' ');
  63.                 }
  64.             }
  65.  
  66.             // print right part of diamonds
  67.             for (int right = width / 2 + i; right < width; right++)
  68.             {
  69.                 if (right % 2 == 1)
  70.                 {
  71.                     Console.Write('/');
  72.                 }
  73.                 else
  74.                 {
  75.                     Console.Write(' ');
  76.                 }
  77.             }
  78.  
  79.             // print dots to the right
  80.             Console.Write(new string('.', i));
  81.  
  82.             Console.WriteLine();
  83.         }
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement