Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Demo
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- int m = int.Parse(Console.ReadLine());
- var matrix = new string[n, m];
- //Input
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < m; j++)
- {
- matrix[i, j] = Console.ReadLine();
- }
- }
- //Rows
- int tempCount = 1, count = 1;
- string element = string.Empty;
- for (int row = 0; row < n; row++)
- {
- for (int col = 0; col < m - 1; col++)
- {
- if (matrix[row, col] == matrix[row, col + 1])
- {
- tempCount++;
- if (count < tempCount)
- {
- count = tempCount;
- element = matrix[row, col];
- }
- }
- }
- tempCount = 1;
- }
- //Collums
- for (int col = 0; col < m; col++)
- {
- for (int row = 0; row < n - 1; row++)
- {
- if (matrix[row, col] == matrix[row + 1, col])
- {
- tempCount++;
- if (count < tempCount)
- {
- count = tempCount;
- element = matrix[row, col];
- }
- }
- }
- tempCount = 1;
- }
- //Diagonal
- for (int i = 0; i < n - 1; i++)
- {
- if (matrix[i, i] == matrix[i + 1, i + 1])
- {
- tempCount++;
- if (count < tempCount)
- {
- count = tempCount;
- element = matrix[i, i];
- }
- }
- }
- //Output
- while (count > 0)
- {
- Console.Write($"{element} ");
- count--;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment