Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- class LargestCommonEnd
- {
- static void Main(string[] args)
- {
- string[] arr = Console.ReadLine()
- .Split(new char[] { ' ' },
- StringSplitOptions.
- RemoveEmptyEntries);
- string[] arr2 = Console.ReadLine()
- .Split(new char[] { ' ' },
- StringSplitOptions.
- RemoveEmptyEntries);
- int LeftCount = CommonMaxEnd(arr, arr2);
- Array.Reverse(arr);
- arr2 = arr2.Reverse().ToArray();
- int RightCount = CommonMaxEnd(arr, arr2);
- Console.WriteLine($"{Math.Max(LeftCount, RightCount)}");
- }
- private static int CommonMaxEnd(string[] arr, string[] arr2)
- {
- int Similar = Math.Min(arr.Length, arr2.Length);
- int count = 0;
- for (int i = 0; i < Similar; i++)
- {
- if (arr[i] == arr2[i])
- {
- count++;
- }
- else
- {
- break;
- }
- }
- return count;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement