settingsAccountsettings
By using our mini forum, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy
Menusettings

Q: Problem solving in C# Task - Summertime for Programmers - Half Beer

+3 votes

Dimitrichko has a dream – to become the best programmer ever. He is studying at SoftUni, investing all of his free time doing homework and watching videos. He enjoys drinking beer, but he doesn’t have time for this. Your task is to draw him one and make him happy. Beware that he may get tipsy very easy. Fill exactly half of the bottle with beer.

You are given an integer number N (always odd). The width of the bottom of the bottle should be 2 * N. The width of the top of the bottle should be N + 1. The height of the bottle should be 3 * N + 1. Check the examples below to understand your task better.

Input:

The input number N should be read from the console. It will be odd number in the range [3..59].
The input data will always be valid and in the format described. There is no need to check it explicitly.

Output:

The output should be printed on the console. Use the “*” to draw the bottle and fill it with “.” and “@”. Follow the examples below.

Constraints:

  • N will always be a positive odd number in the range [359].
  • Allowed working time for your program: 0.1 seconds. Allowed memory: 16 MB.

Examples:

summertime1

summertime2

asked in C# category by user hues
edited by user golearnweb

1 Answer

+2 votes
 
Best answer

These kind of tasks in C# are almost the same - you can solve them by finding similar logic.

...and here are my screenshots for the half beer:

beer1

beer2

And here is my CODE:

using System;

class Summertime
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());

        Console.WriteLine("{0}{1}{0}",
            new string((' '), ((2 * n) - (n + 1)) / 2),
            new string(('*'), n + 1));

        for (int i = 0; i < n / 2 + 1; i++)//0,1,2;
        {
            Console.WriteLine("{0}*{1}*{0}",
                new string((' '), ((2 * n) - (n + 1)) / 2),
                new string((' '), (n + 1) - 2));
        }
        
        for (int i = 0; i < n / 2 - 1; i++)//0,1,2
        {
            Console.WriteLine("{0}*{1}*{0}",
                new string((' '), n / 2 - i - 1),
                new string((' '), n + 1 + 2 * i));
        }
        
        for (int i = 0; i < n; i++)
        {
            Console.WriteLine("*{0}*",
                new string(('.'), (2 * n - 2)));
        }

        for (int i = 0; i < n; i++)
        {
            Console.WriteLine("*{0}*",
                new string(('@'), (2 * n - 2)));
        }

        Console.WriteLine("{0}",
            new string(('*'), 2 * n));
    }
}
answered by user nikole
edited by user golearnweb
tahnsk! it really makes sense now!
...