kirililchev3

Largest Common End

Jun 3rd, 2018
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.99 KB | None | 0 0
  1. namespace Largest_Common_End
  2. {
  3.     using System;
  4.  
  5.     public class LargestCommonEnd
  6.     {
  7.         public static void Main(string[] args)
  8.         {
  9.             string[] arr1 = Console.ReadLine().Split(' ');
  10.             string[] arr2 = Console.ReadLine().Split(' ');
  11.  
  12.             int leftToRight = 0, rightToLeft = 0, minLength = Math.Min(arr1.Length, arr2.Length);
  13.  
  14.             for (int i = 0; i < minLength; i++)
  15.             {
  16.                 if (arr1[i].Equals(arr2[i]))
  17.                 {
  18.                     leftToRight++;
  19.                     continue;
  20.                 }
  21.  
  22.                 break;
  23.             }
  24.  
  25.             for (int i = 1; i <= minLength; i++)
  26.             {
  27.                 if (arr1[arr1.Length - i].Equals(arr2[arr2.Length - i]))
  28.                 {
  29.                     rightToLeft++;
  30.                     continue;
  31.                 }
  32.  
  33.                 break;
  34.             }
  35.  
  36.             Console.WriteLine(Math.Max(leftToRight, rightToLeft));
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment