fbinnzhivko

03.01 Wine Glass

Apr 17th, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.80 KB | None | 0 0
  1. using System;
  2. class Program
  3. {
  4.     static void Main()
  5.     {
  6.         int n = int.Parse(Console.ReadLine());
  7.  
  8.         int counter = 0; // used to count the printed rows
  9.  
  10.         int stars = n - 2; // initial number of stars
  11.         int dots = 0; // initial number of dots
  12.  
  13.         // printing the first half of the glass
  14.         for (int i = 0; i < n / 2; i++)
  15.         {
  16.             Console.Write(new string('.', dots));
  17.             Console.Write("\\");
  18.             Console.Write(new string('*', stars));
  19.             Console.Write("/");
  20.             Console.WriteLine(new string('.', dots));
  21.             dots++;
  22.             stars -= 2;
  23.             counter++;
  24.         }
  25.         dots--; //in every iteration (even the last one) we increase the value of "dots" by one
  26.                 // that's why we must now decrease it just once. See what happens when you remove the line above :)
  27.  
  28.         //check whether n is more than 12 or not (described in the problem)
  29.         //printing the stem
  30.         if (n >= 12)
  31.         {
  32.             for (int i = 0; i < (n / 2) - 2; i++)
  33.             {
  34.                 Console.Write(new string('.', dots));
  35.                 Console.Write("||");
  36.                 Console.WriteLine(new string('.', dots));
  37.                 counter++; // we still use the "counter" variable
  38.             }
  39.         }
  40.         else
  41.         {
  42.             for (int i = 0; i < (n / 2) - 1; i++)
  43.             {
  44.                 Console.Write(new string('.', dots));
  45.                 Console.Write("||");
  46.                 Console.WriteLine(new string('.', dots));
  47.                 counter++;
  48.             }
  49.         }
  50.         //printing the remaining rows
  51.         for (int i = 0; i < n - counter; i++)//time to use counter
  52.         {
  53.             Console.WriteLine(new string('-', n));
  54.         }
  55.     }
  56. }
Add Comment
Please, Sign In to add comment