kirililchev3

Symbol in Matrix

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