3
06/11/2024 6:42 pm
Topic starter
Once upon a time there was a kingdom and everyone in the kingdom was a thief. Izzy wanted to become the King of Thieves and so started stealing only perfect gems from other thieves. Help Izzy by showing him what a perfect gem with given parameters should look like.
Input
The input data should be read from the console.
- The first line will hold the size of the gem – n.
- The second line will hold the type of the gem – a symbol: e.g. ‘*’.
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. It should consist of ‘n’ lines, holding the gem.
Constraints
- The number n will be a positive odd integer between 3 and 59, inclusive.
- The type of the gem will be a symbol from the standard ASCII table.
- Allowed working time for your program: 0.1 seconds.
- Allowed memory: 16 MB.
Examples
1 Answer
2
06/11/2024 6:43 pm
These drwing C# tasks are very amusing 🙂 Really enjoy solving them!
Here's my solution for tis one:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class KingOfThieves { static void Main() { int n = int.Parse(Console.ReadLine()); char symbol = char.Parse(Console.ReadLine()); for (int i = 0; i < n / 2; i++) { Console.WriteLine("{0}{1}{0}", new string(('-'), n / 2 - i), new string((symbol), 1 + 2 * i)); } Console.WriteLine("{0}", new string((symbol), n)); for (int i = 0; i < n / 2; i++) { Console.WriteLine("{0}{1}{0}", new string(('-'), 1 + i), new string((symbol), n - ((1 + i) * 2))); } } }
BTW - the middle line is static - in the yellow color: