fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication3
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. MartiniGlass martiniGlass = new MartiniGlass();
  14. martiniGlass.PrintGlass(4);
  15. Console.ReadLine();
  16. }
  17. }
  18.  
  19. class MartiniGlass
  20. {
  21. private const char GlassTop = '0';
  22. private const char GlassHandle = '|';
  23. private const char GlassBottom = '=';
  24.  
  25. public void PrintGlass(int GlassSize)
  26. {
  27. int width = CalcGlassWidth(GlassSize);
  28.  
  29. PrintGlassTop(GlassSize, width);
  30. PrintGlassHandle(GlassSize, GlassSize - 1);
  31. PrintGlassBase(width);
  32. }
  33.  
  34. private int CalcGlassWidth(int size)
  35. {
  36. int width = 1;
  37. width += 2 * (size - 1);
  38.  
  39. return width;
  40. }
  41.  
  42. private void PrintGlassTop(int size, int width)
  43. {
  44. for (int i = 0; i < size; i++)
  45. {
  46. PrintLineOfChars(i, ' ');
  47. PrintLineOfChars(width, GlassTop);
  48.  
  49. width -= 2;
  50. Console.WriteLine();
  51. }
  52. }
  53.  
  54. private void PrintGlassHandle(int size, int startPos)
  55. {
  56. for (int i = 0; i < size; i++)
  57. {
  58. PrintLineOfChars(startPos, ' ');
  59. Console.WriteLine(GlassHandle);
  60. }
  61. }
  62.  
  63. private void PrintGlassBase(int width)
  64. {
  65. PrintLineOfChars(width, GlassBottom);
  66. }
  67.  
  68. private void PrintLineOfChars(int amount, char symbol)
  69. {
  70. for (int i = 0; i < amount; i++)
  71. Console.Write(symbol);
  72. }
  73. }
  74. }
  75.  
Success #stdin #stdout 0.01s 14636KB
stdin
Standard input is empty
stdout
0000000
 00000
  000
   0
   |
   |
   |
   |
=======