Advertisement
alidzhikov

FillTheMatrix

May 8th, 2015
1,521
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.61 KB | None | 0 0
  1. using System;
  2. class FillTheMatrix
  3. {
  4.     static void Main()
  5.     {
  6.         int rowsAndColsSize = int.Parse(Console.ReadLine());
  7.         char pattern = (char)Console.Read();
  8.  
  9.         int[,] matrix = new int[rowsAndColsSize, rowsAndColsSize];
  10.         int currentNumber = 1;
  11.         if (Char.ToUpper(pattern).Equals('A'))
  12.         {
  13.             for (int col = 0; col < rowsAndColsSize; col++)
  14.             {
  15.                 for (int row = 0; row < rowsAndColsSize; row++)
  16.                 {
  17.                     matrix[row, col] = currentNumber;
  18.                     currentNumber++;
  19.                 }
  20.             }
  21.         }
  22.         else if (Char.ToUpper(pattern).Equals('B'))
  23.         {
  24.             for (int col = 0; col < rowsAndColsSize; col++)
  25.             {
  26.                 if (col % 2 == 0)
  27.                 {
  28.                     for (int row = 0; row < rowsAndColsSize; row++)
  29.                     {
  30.                         matrix[row, col] = currentNumber;
  31.                         currentNumber++;
  32.                     }
  33.                 }
  34.                 else
  35.                 {
  36.                     for (int row = rowsAndColsSize - 1; row >= 0; row--)
  37.                     {
  38.                         matrix[row, col] = currentNumber;
  39.                         currentNumber++;
  40.                     }
  41.                 }
  42.             }
  43.         }
  44.  
  45.         for (int row = 0; row < rowsAndColsSize; row++)
  46.         {
  47.             for (int col = 0; col < rowsAndColsSize; col++)
  48.             {
  49.                 Console.Write("{0,2} ", matrix[row, col]);
  50.             }
  51.             Console.WriteLine();
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement