Advertisement
Guest User

Untitled

a guest
Oct 8th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. class LargestCommonEnd
  5. {
  6.     static void Main(string[] args)
  7.     {
  8.         string[] arr = Console.ReadLine()
  9.             .Split(new char[] { ' ' },
  10.                 StringSplitOptions.
  11.                     RemoveEmptyEntries);
  12.         string[] arr2 = Console.ReadLine()
  13.             .Split(new char[] { ' ' },
  14.                 StringSplitOptions.
  15.                     RemoveEmptyEntries);
  16.         int LeftCount = CommonMaxEnd(arr, arr2);
  17.         Array.Reverse(arr);
  18.         arr2 = arr2.Reverse().ToArray();
  19.         int RightCount = CommonMaxEnd(arr, arr2);
  20.         Console.WriteLine($"{Math.Max(LeftCount, RightCount)}");
  21.  
  22.     }
  23.     private static int CommonMaxEnd(string[] arr, string[] arr2)
  24.     {
  25.         int Similar = Math.Min(arr.Length, arr2.Length);
  26.         int count = 0;
  27.         for (int i = 0; i < Similar; i++)
  28.         {
  29.             if (arr[i] == arr2[i])
  30.             {
  31.                 count++;
  32.             }
  33.             else
  34.             {
  35.                 break;
  36.             }
  37.         }
  38.         return count;
  39.  
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement