Advertisement
martyz

Largest Common End

Oct 7th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 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 LargestCommonEnd
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string[] arr1 = Console.ReadLine().Split(new char[0], StringSplitOptions.RemoveEmptyEntries).ToArray();
  14.             string[] arr2 = Console.ReadLine().Split(new char[0], StringSplitOptions.RemoveEmptyEntries).ToArray();
  15.             int loop = Math.Min(arr1.Length, arr2.Length); // old  int loop = Math.Min(arr1.Length, arr2.Length) - 1;
  16.  
  17.             int left = 0; int right = 0;
  18.  
  19.             for (int i = 0; i < loop; i++)
  20.             {
  21.                 if (arr1[i] == arr2[i])
  22.                 {
  23.                     left++;
  24.                 }
  25.                 if (arr1[arr1.Length - i - 1] == arr2[arr2.Length - i - 1])
  26.                 {
  27.                     right++;
  28.                 }
  29.             }
  30.             if (left + right !=0)
  31.             {
  32.                 Console.WriteLine(Math.Max(left, right));
  33.             }
  34.             else
  35.             {
  36.                 Console.WriteLine(0);
  37.             }
  38.          }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement