Guest User

LCE

a guest
Oct 5th, 2016
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.08 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _01.Largest_Common_End
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var arr1 = Console.ReadLine().Split(' ').ToArray();
  14.             var arr2 = Console.ReadLine().Split(' ').ToArray();
  15.  
  16.             int counterLeft = 0;
  17.             int counterRight = 0;
  18.  
  19.             int iterationsCount = Math.Min(arr1.Length, arr2.Length);
  20.  
  21.             for (int i = 0; i < iterationsCount; i++)
  22.             {
  23.                 if (arr1[i] == arr2[i])
  24.                 {
  25.                     counterLeft++;
  26.                 }
  27.             }
  28.             int index = 1;
  29.             for (int i = iterationsCount - 1; i >= 0; i--)
  30.             {
  31.                 if (arr1[arr1.Length - index] == arr2[arr2.Length - index])
  32.                 {
  33.                     counterRight++;
  34.                     index++;
  35.                 }
  36.             }
  37.  
  38.             Console.WriteLine(Math.Max(counterLeft, counterRight));
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment