Advertisement
Guest User

WineGlass

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