j0nze

Triangle

Nov 19th, 2017
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.93 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp4
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int n = int.Parse(Console.ReadLine());
  14.  
  15.             //Широчина = (4 * n) + 1;
  16.             //Височина = (2 * н) + 1;
  17.             int width = 4 * n + 1;
  18.             Console.WriteLine("{0}", new string('#', 4 * n + 1));
  19.             int hashtag = 4 * n + 1;
  20.             int spacing = 1;
  21.             for (int i = 1; i <= n; i++)
  22.             {
  23.                 if (i == n / 2 + 1)
  24.                 {
  25.                     if (n % 2 == 0)
  26.                     {
  27.                         Console.WriteLine("{0}{1}{2}(@){2}{1}{0}",
  28.                             new string('.', i),
  29.                             new string('#', n - 1),
  30.                             new string(' ', n / 2 - 1));
  31.                     }
  32.                     else
  33.                     {
  34.                         Console.WriteLine("{0}{1}{2}(@){2}{1}{0}",
  35.                             new string('.',i),
  36.                             new string('#', n),
  37.                             new string(' ', (width - (i * 2) - (n * 2) - 3) / 2));
  38.                     }
  39.                     spacing += 2;
  40.                     continue;
  41.                 }
  42.                 Console.WriteLine("{0}{1}{2}{1}{0}",
  43.                     new string('.', i),
  44.                     new string('#', (hashtag - 2 * i - spacing) / 2),
  45.                     new string(' ', spacing));
  46.                 spacing += 2;
  47.             }
  48.             int hashtagBot = n * 2 - 1;
  49.             for (int i = 0; i < n; i++)
  50.             {
  51.                 Console.WriteLine("{0}{1}{0}",
  52.                     new string('.', (width - hashtagBot) / 2),
  53.                     new string('#', hashtagBot));
  54.  
  55.                 hashtagBot -= 2;
  56.             }          
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment