Advertisement
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 _1.Largest_Common_End
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] array1 = Console.ReadLine().Split(' ');
- string[] array2 = Console.ReadLine().Split(' ');
- int largestArrayCount = array1.Length > array2.Length ? array1.Length : array2.Length;
- bool leftSideMatch = true;
- bool rightSideMatch = true;
- int leftCount = 0;
- int rightCount = 0;
- bool KeyExist = false;
- for (int i = 0; i < largestArrayCount; i++)
- {
- KeyExist = array1.Length > i && array2.Length > i ? true : false;
- if (KeyExist && (!string.IsNullOrEmpty(array1[i]) || !string.IsNullOrEmpty(array2[i])) && leftSideMatch)
- {
- if (array1[i] == array2[i])
- {
- leftCount++;
- }
- else
- {
- leftSideMatch = false;
- }
- }
- KeyExist = array1.Length > array1.Length - 1 - i && array2.Length > array2.Length - 1 - i ? true : false;
- if (KeyExist && (!string.IsNullOrEmpty(array1[array1.Length - 1 - i]) || !string.IsNullOrEmpty(array2[array2.Length - 1 - i])) && rightSideMatch)
- {
- if (array1[array1.Length - 1 - i] == array2[array2.Length - 1 - i])
- {
- rightCount++;
- }
- else
- {
- rightSideMatch = false;
- }
- }
- if (rightSideMatch == false && leftSideMatch == false)
- {
- break;
- }
- }
- Console.WriteLine(leftCount > rightCount ? leftCount : rightCount);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement