Advertisement
nevenailievaa

2201682020-Domashno2

Oct 9th, 2022
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.98 KB | None | 0 0
  1. namespace Task_2
  2. {
  3.     using System;
  4.  
  5.     class Task_2
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int n = int.Parse(Console.ReadLine());
  10.  
  11.             char[,] matrix = FillMatrix(n);
  12.  
  13.             int globalMax = 0;
  14.             char globalChar = (char)0;
  15.  
  16.             RenderRows(matrix, ref globalMax, ref globalChar);
  17.             RenderCols(matrix, ref globalMax, ref globalChar);
  18.             RenderMainDiagonal(matrix, ref globalMax, ref globalChar);
  19.             RenderSecondDiagonal(matrix, ref globalMax, ref globalChar);
  20.  
  21.             for (int i = 0; i < globalMax; i++)
  22.             {
  23.                 if (i < globalMax - 1)
  24.                 {
  25.                     Console.Write($"{globalChar} ");
  26.                 }
  27.                 else
  28.                 {
  29.                     Console.WriteLine($"{globalChar}");
  30.                 }
  31.             }
  32.         }
  33.  
  34.  
  35.         static void RenderRows(char[,] matrix, ref int globalMax, ref char globalChar)
  36.         {
  37.             for (int row = 0; row < matrix.GetLength(0); row++)
  38.             {
  39.                 char[] temp = new char[matrix.GetLength(1)];
  40.  
  41.                 for (int col = 0; col < matrix.GetLength(1); col++)
  42.                 {
  43.                     temp[col] = matrix[row, col];
  44.                 }
  45.  
  46.                 SetMaxSecuense(temp, ref globalMax, ref globalChar);
  47.             }
  48.         }
  49.  
  50.         static void RenderCols(char[,] matrix, ref int globalMax, ref char globalChar)
  51.         {
  52.             for (int col = 0; col < matrix.GetLength(1); col++)
  53.             {
  54.                 char[] temp = new char[matrix.GetLength(0)];
  55.  
  56.                 for (int row = 0; row < matrix.GetLength(0); row++)
  57.                 {
  58.                     temp[row] = matrix[row, col];
  59.                 }
  60.  
  61.                 SetMaxSecuense(temp, ref globalMax, ref globalChar);
  62.             }
  63.         }
  64.  
  65.         static void RenderMainDiagonal(char[,] matrix, ref int globalMax, ref char globalChar)
  66.         {
  67.             char[] temp = new char[matrix.GetLength(0)];
  68.             for (int row = 0; row < matrix.GetLength(0); row++)
  69.             {
  70.                 temp[row] = matrix[row, row];
  71.             }
  72.  
  73.             SetMaxSecuense(temp, ref globalMax, ref globalChar);
  74.         }
  75.  
  76.         static void RenderSecondDiagonal(char[,] matrix, ref int globalMax, ref char globalChar)
  77.         {
  78.             char[] temp = new char[matrix.GetLength(0)];
  79.             for (int row = 0; row < matrix.GetLength(0); row++)
  80.             {
  81.                 temp[row] = matrix[row, matrix.GetLength(0) -  1 - row];
  82.             }
  83.  
  84.             SetMaxSecuense(temp, ref globalMax, ref globalChar);
  85.         }
  86.  
  87.         static void SetMaxSecuense(char[] temp, ref int globalMax, ref char globalChar)
  88.         {
  89.             char currentChar = temp[0];
  90.             int currentMax = 1;
  91.  
  92.             for (int i = 1; i < temp.Length; i++)
  93.             {
  94.                 if (temp[i] == currentChar)
  95.                 {
  96.                     currentMax++;
  97.                 }
  98.                 else
  99.                 {
  100.                     if (currentMax > globalMax)
  101.                     {
  102.                         globalMax = currentMax;
  103.                         globalChar = currentChar;
  104.                     }
  105.  
  106.                     currentChar = temp[i];
  107.                     currentMax = 1;
  108.                 }
  109.             }
  110.  
  111.             if (currentMax > globalMax)
  112.             {
  113.                 globalMax = currentMax;
  114.                 globalChar = currentChar;
  115.             }
  116.         }
  117.         static char[,] FillMatrix(int n)
  118.         {
  119.             char[,] matrix = new char[n, n];
  120.  
  121.             for (int row = 0; row < matrix.GetLength(0); row++)
  122.             {
  123.                 char[] temp = Console.ReadLine().ToCharArray();
  124.  
  125.                 for (int col = 0; col < matrix.GetLength(1); col++)
  126.                 {
  127.                     matrix[row, col] = temp[col];
  128.                 }
  129.             }
  130.  
  131.             return matrix;
  132.         }
  133.  
  134.  
  135.     }
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement