Advertisement
Guest User

Sequence in Matrix

a guest
Nov 13th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.67 KB | None | 0 0
  1. using System;
  2.  
  3. namespace SequenceinMatrix.cs
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string[] rowsCols = Console.ReadLine().Split(" ");
  10.             int height = int.Parse(rowsCols[0]);
  11.             int width = int.Parse(rowsCols[1]);
  12.             string[,] matrix = new string[height, width];
  13.             int bestLenght = 1;
  14.             int result = 1;
  15.             for (int i = 0; i < matrix.GetLength(0); i++)
  16.             {
  17.                 string[] numbers = Console.ReadLine().Split(" ");
  18.                
  19.                 for (int j = 0; j < matrix.GetLength(1); j++)
  20.                 {
  21.                    
  22.                     matrix[j, i] = numbers[j];
  23.                 }
  24.                
  25.             }
  26.             for (int k = 1; k < matrix.GetLength(0); k++)
  27.             {
  28.                
  29.                 for (int i = 1; i < matrix.GetLength(1); i++)
  30.                 {
  31.                     if (matrix[k, i] == matrix[k , i - 1] )
  32.                     {
  33.                         bestLenght++;
  34.                     }
  35.                     else
  36.                     {
  37.                         bestLenght = 1;
  38.                        
  39.                     }
  40.                     if(bestLenght >= result)
  41.                     {
  42.                         result = bestLenght;
  43.                     }
  44.                 }
  45.             }
  46.             for (int k = 1; k < matrix.GetLength(0); k++)
  47.             {
  48.                
  49.                 for (int i = 1; i < matrix.GetLength(1); i++)
  50.                 {
  51.                     int sum = 1;
  52.                     if (matrix[k, i] == matrix[k - 1, i])
  53.                     {
  54.                         sum++;
  55.                     }
  56.                     else
  57.                     {
  58.                         sum = 1;
  59.                        
  60.                     }
  61.                     if (sum >= result)
  62.                     {
  63.                         result = sum;
  64.                     }
  65.                 }
  66.             }
  67.             for (int k = 1; k < matrix.GetLength(0); k++)
  68.             {
  69.                 int count = 1;
  70.                 for (int i = 1; i < matrix.GetLength(1); i++)
  71.                 {
  72.                     if (matrix[k, i] == matrix[k - 1, i - 1])
  73.                     {
  74.                         count++;
  75.                        
  76.                     }
  77.                     else
  78.                     {
  79.                         count = 1;
  80.                     }
  81.                     if (count >= result)
  82.                     {
  83.                         result = count;
  84.                     }
  85.                 }
  86.             }
  87.             Console.WriteLine(result);
  88.  
  89.         }
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement