Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace LargestCommonEnd
- {
- class LargeCommonEnd
- {
- static void Main()
- {
- string[] firstArr = Console.ReadLine().Split();
- string[] secondArr = Console.ReadLine().Split();
- int smallerArr = Math.Min(firstArr.Length, secondArr.Length);
- int leftCounter = CheckArrays(firstArr, secondArr, smallerArr);
- Array.Reverse(firstArr);
- Array.Reverse(secondArr);
- int rightCounter = CheckArrays(firstArr, secondArr, smallerArr);
- Console.WriteLine(Math.Max(leftCounter,rightCounter));
- }
- public static int CheckArrays(string[] firstArr, string[] secondArr, int smallerArr)
- {
- int counter = 0;
- for (int i = 0; i < smallerArr; i++)
- {
- if (firstArr[i] == secondArr[i])
- {
- counter++;
- }
- else
- {
- break;
- }
- }
- return counter;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment