Advertisement
Guest User

Problem 4 - Eggcelent

a guest
Apr 5th, 2014
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.54 KB | None | 0 0
  1. using System;
  2.  
  3. class Program
  4. {
  5.     static void Main()
  6.     {
  7.         int n = int.Parse(Console.ReadLine());
  8.  
  9.         int eggHeight = 2 * n;
  10.         int eggWidth = 3 * n - 1;
  11.         int totalWidth = 3 * n + 1;
  12.  
  13.         char[,] matrix = new char[eggHeight, totalWidth];
  14.  
  15.         FillMatrix(eggHeight, totalWidth, matrix);
  16.  
  17.         int topRow = 0;
  18.         int bottomRow = eggHeight - 1;
  19.  
  20.         int leftPivot = (n + 1);
  21.         for (int i = 0; i < n - 1; i++, leftPivot++)
  22.         {
  23.             matrix[topRow, leftPivot] = '*';
  24.             matrix[bottomRow, leftPivot] = '*';
  25.         }
  26.  
  27.  
  28.         // reseting the pivot
  29.         int rightPivot = leftPivot + 1;
  30.         leftPivot = n - 1;
  31.         topRow++;
  32.         bottomRow--;
  33.         for (int i = 0; i < n / 2; i++)
  34.         {
  35.             matrix[topRow, leftPivot] = '*';
  36.             matrix[bottomRow, leftPivot] = '*';
  37.             matrix[topRow, rightPivot] = '*';
  38.             matrix[bottomRow, rightPivot] = '*';
  39.             if (i != n / 2 - 1)
  40.             {
  41.                 leftPivot -= 2;
  42.                 rightPivot += 2;
  43.                 topRow++;
  44.                 bottomRow--;
  45.             }
  46.         }
  47.  
  48.         topRow++;
  49.         for (int i = 0; i < n - 2; i++)
  50.         {
  51.             matrix[topRow, leftPivot] = '*';
  52.             matrix[topRow, rightPivot] = '*';
  53.             topRow++;
  54.         }
  55.  
  56.         // reset
  57.         topRow = n - 1;
  58.         bottomRow = n;
  59.         leftPivot++;
  60.         for (int i = 0; i < eggWidth - 2; i++)
  61.         {
  62.             if (i % 2 == 0)
  63.             {
  64.                 matrix[topRow, leftPivot] = '@';
  65.                 matrix[bottomRow, leftPivot] = '.';
  66.             }
  67.             else
  68.             {
  69.                 matrix[topRow, leftPivot] = '.';
  70.                 matrix[bottomRow, leftPivot] = '@';
  71.             }
  72.             leftPivot++;
  73.         }
  74.  
  75.         PrintMatrix(eggHeight, totalWidth, matrix);
  76.     }
  77.  
  78.     private static void PrintMatrix(int eggHeight, int totalWidth, char[,] matrix)
  79.     {
  80.         for (int row = 0; row < eggHeight; row++)
  81.         {
  82.             for (int col = 0; col < totalWidth; col++)
  83.             {
  84.                 Console.Write(matrix[row, col]);
  85.             }
  86.             Console.WriteLine();
  87.         }
  88.     }
  89.  
  90.     private static void FillMatrix(int eggHeight, int totalWidth, char[,] matrix)
  91.     {
  92.         for (int row = 0; row < eggHeight; row++)
  93.         {
  94.             for (int col = 0; col < totalWidth; col++)
  95.             {
  96.                 matrix[row, col] = '.';
  97.             }
  98.         }
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement