settingsAccountsettings
Menusettings

Q: The Explorer - Drawing C# Task

+9 votes

Bai Vylcho is very an enthusiastic explorer. His passion are the diamonds, he just adores them. Today he is going on an expedition to collect all kind of diamonds, no matter small or large. Help your friend to find all the diamonds in the biggest known cave "The Console Cave". At the only input line you will be given the width of the diamond. The char that forms the outline of the diamonds is '*' and the surrounding parts are made of '-' (see the examples). Your task is to print a diamond of given size n.

Input

Input data should be read from the console.

  • The only input line will hold the width of the diamond – n.

The input data will always be valid and in the format described. There is no need to check it explicitly.

Output

The output data must be printed on the console.

  • The output lines should hold the diamond.

Constraints

  • The number n is positive odd integer between 3 and 59, inclusive.
  • Allowed working time for your program: 0.25 seconds.
  • Allowed memory: 16 MB.

Examples

the explorer drawing c# task

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

1 Answer

+2 votes
 
Best answer

Here's my solution matthew44:

using System;

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

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

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

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

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

        Console.WriteLine("{0}{1}{0}",
            new string('-', n / 2),
            new string('*', 1));//5TH PART = 1ST PART- STATIC
    }
}

 

answered by user mitko
selected by user golearnweb
...