Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Task_2
- {
- using System;
- class Task_2
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- char[,] matrix = FillMatrix(n);
- int globalMax = 0;
- char globalChar = (char)0;
- RenderRows(matrix, ref globalMax, ref globalChar);
- RenderCols(matrix, ref globalMax, ref globalChar);
- RenderMainDiagonal(matrix, ref globalMax, ref globalChar);
- RenderSecondDiagonal(matrix, ref globalMax, ref globalChar);
- for (int i = 0; i < globalMax; i++)
- {
- if (i < globalMax - 1)
- {
- Console.Write($"{globalChar} ");
- }
- else
- {
- Console.WriteLine($"{globalChar}");
- }
- }
- }
- static void RenderRows(char[,] matrix, ref int globalMax, ref char globalChar)
- {
- for (int row = 0; row < matrix.GetLength(0); row++)
- {
- char[] temp = new char[matrix.GetLength(1)];
- for (int col = 0; col < matrix.GetLength(1); col++)
- {
- temp[col] = matrix[row, col];
- }
- SetMaxSecuense(temp, ref globalMax, ref globalChar);
- }
- }
- static void RenderCols(char[,] matrix, ref int globalMax, ref char globalChar)
- {
- for (int col = 0; col < matrix.GetLength(1); col++)
- {
- char[] temp = new char[matrix.GetLength(0)];
- for (int row = 0; row < matrix.GetLength(0); row++)
- {
- temp[row] = matrix[row, col];
- }
- SetMaxSecuense(temp, ref globalMax, ref globalChar);
- }
- }
- static void RenderMainDiagonal(char[,] matrix, ref int globalMax, ref char globalChar)
- {
- char[] temp = new char[matrix.GetLength(0)];
- for (int row = 0; row < matrix.GetLength(0); row++)
- {
- temp[row] = matrix[row, row];
- }
- SetMaxSecuense(temp, ref globalMax, ref globalChar);
- }
- static void RenderSecondDiagonal(char[,] matrix, ref int globalMax, ref char globalChar)
- {
- char[] temp = new char[matrix.GetLength(0)];
- for (int row = 0; row < matrix.GetLength(0); row++)
- {
- temp[row] = matrix[row, matrix.GetLength(0) - 1 - row];
- }
- SetMaxSecuense(temp, ref globalMax, ref globalChar);
- }
- static void SetMaxSecuense(char[] temp, ref int globalMax, ref char globalChar)
- {
- char currentChar = temp[0];
- int currentMax = 1;
- for (int i = 1; i < temp.Length; i++)
- {
- if (temp[i] == currentChar)
- {
- currentMax++;
- }
- else
- {
- if (currentMax > globalMax)
- {
- globalMax = currentMax;
- globalChar = currentChar;
- }
- currentChar = temp[i];
- currentMax = 1;
- }
- }
- if (currentMax > globalMax)
- {
- globalMax = currentMax;
- globalChar = currentChar;
- }
- }
- static char[,] FillMatrix(int n)
- {
- char[,] matrix = new char[n, n];
- for (int row = 0; row < matrix.GetLength(0); row++)
- {
- char[] temp = Console.ReadLine().ToCharArray();
- for (int col = 0; col < matrix.GetLength(1); col++)
- {
- matrix[row, col] = temp[col];
- }
- }
- return matrix;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement