Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Wintellect.PowerCollections;
- namespace TestGround
- {
- class Program
- {
- public static void Main()
- {
- string[] arr = Console.ReadLine().Split(' ');
- string[] arr2 = Console.ReadLine().Split(' ');
- int countFront = CountFront(arr, arr2);
- int countBack = CountBack(arr, arr2);
- Console.WriteLine(Math.Max(countFront, countBack));
- }
- private static int CountFront(string[] arr, string[] arr2)
- {
- int counter = 0;
- for (int i = 0; i < Math.Min(arr.Length, arr2.Length); i++)
- {
- if (arr[i] == arr2[i])
- {
- counter++;
- }
- else
- {
- break;
- }
- }
- return counter;
- }
- private static int CountBack(string[] arr, string[] arr2)
- {
- string[] bigger;
- string[] smaller;
- if (arr.Length >= arr2.Length)
- {
- bigger = arr;
- smaller = arr2;
- }
- else
- {
- bigger = arr2;
- smaller = arr;
- }
- int sizeDifference = bigger.Length - smaller.Length;
- int counter = 0;
- for (int i = bigger.Length - 1; i >= sizeDifference; i--)
- {
- if (bigger[i] == smaller[i - sizeDifference])
- {
- counter++;
- }
- else
- {
- break;
- }
- }
- return counter;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement