Advertisement
gabi11

Multidimensional Arrays - 4. Symbol in Matrix

May 12th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.20 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6.  
  7. namespace Advanced
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int dimentions = int.Parse(Console.ReadLine());
  14.  
  15.             int rows = dimentions;
  16.             int cols = dimentions;
  17.  
  18.             var matrix = new int[rows, cols];
  19.  
  20.             for (int row = 0; row < rows; row++)
  21.             {
  22.                 var currentRow = Console.ReadLine().ToArray();
  23.  
  24.                 for (int col = 0; col < cols; col++)
  25.                 {
  26.                     matrix[row, col] = currentRow[col];
  27.                 }
  28.             }
  29.  
  30.             char symbol = char.Parse(Console.ReadLine());
  31.  
  32.             for (int row = 0; row < rows; row++)
  33.             {
  34.                 for (int col = 0; col < cols; col++)
  35.                 {
  36.                     if (matrix[row, col] == symbol)
  37.                     {
  38.                         Console.WriteLine($"({row}, {col})");
  39.                         return;
  40.                     }
  41.                 }
  42.             }
  43.  
  44.             Console.WriteLine($"{symbol} does not occur in the matrix");
  45.  
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement