Advertisement
Teodor92

01. HardMatrix :)

Jan 6th, 2013
901
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.55 KB | None | 0 0
  1. Musing System;
  2.  
  3. class MatrixFour
  4. {
  5.     static void PrintMatrix(int[,] matrix)
  6.     {
  7.         for (int row = 0; row < matrix.GetLength(0); row++)
  8.         {
  9.             for (int col = 0; col < matrix.GetLength(1); col++)
  10.             {
  11.                 Console.Write("{0,4}", matrix[row, col]);
  12.             }
  13.             Console.WriteLine();
  14.             Console.WriteLine();
  15.         }
  16.     }
  17.     static void Main()
  18.     {
  19.         int size = int.Parse(Console.ReadLine());
  20.         int[,] matrix = new int[size, size];
  21.         //int[] dirRow = { 1, 0, -1, 0 };
  22.         //int[] dirCol = { 0, 1, 0, -1 };
  23.         //bool ending = false;
  24.         //while (!ending)
  25.         //{
  26.         //    while (true)
  27.         //    {
  28.                
  29.         //    }
  30.         //}
  31.         int ending = size;
  32.         int start = 0;
  33.         int counter = 1;
  34.         do
  35.         {
  36.             for (int i = start; i < ending; i++)
  37.             {
  38.                 matrix[i, start] = counter;
  39.                 counter++;
  40.             }
  41.             for (int j = start+1; j < ending; j++)
  42.             {
  43.                 matrix[ending - 1,j] = counter;
  44.                 counter++;
  45.             }
  46.             for (int k = ending - 2; k >= start; k--)
  47.             {
  48.                 matrix[k,ending - 1] = counter;
  49.                 counter++;
  50.             }
  51.             for (int p = ending - 2; p >= start + 1; p--)
  52.             {
  53.                 matrix[start, p] = counter;
  54.                 counter++;
  55.             }
  56.             start++;
  57.             ending--;
  58.         }
  59.         while (ending - start > 0);
  60.         PrintMatrix(matrix);
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement