Advertisement
yanchevilian

4.Symbol in Matrix

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