Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace SequenceinMatrix.cs
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] rowsCols = Console.ReadLine().Split(" ");
- int height = int.Parse(rowsCols[0]);
- int width = int.Parse(rowsCols[1]);
- string[,] matrix = new string[height, width];
- int bestLenght = 1;
- int result = 1;
- for (int i = 0; i < matrix.GetLength(0); i++)
- {
- string[] numbers = Console.ReadLine().Split(" ");
- for (int j = 0; j < matrix.GetLength(1); j++)
- {
- matrix[j, i] = numbers[j];
- }
- }
- for (int k = 1; k < matrix.GetLength(0); k++)
- {
- for (int i = 1; i < matrix.GetLength(1); i++)
- {
- if (matrix[k, i] == matrix[k , i - 1] )
- {
- bestLenght++;
- }
- else
- {
- bestLenght = 1;
- }
- if(bestLenght >= result)
- {
- result = bestLenght;
- }
- }
- }
- for (int k = 1; k < matrix.GetLength(0); k++)
- {
- for (int i = 1; i < matrix.GetLength(1); i++)
- {
- int sum = 1;
- if (matrix[k, i] == matrix[k - 1, i])
- {
- sum++;
- }
- else
- {
- sum = 1;
- }
- if (sum >= result)
- {
- result = sum;
- }
- }
- }
- for (int k = 1; k < matrix.GetLength(0); k++)
- {
- int count = 1;
- for (int i = 1; i < matrix.GetLength(1); i++)
- {
- if (matrix[k, i] == matrix[k - 1, i - 1])
- {
- count++;
- }
- else
- {
- count = 1;
- }
- if (count >= result)
- {
- result = count;
- }
- }
- }
- Console.WriteLine(result);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement