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 _01.Largest_Common_End
- {
- class LargestCommonEnd
- {
- static void Main(string[] args)
- {
- string[] words1 = Console.ReadLine().Split().ToArray();
- string[] words2 = Console.ReadLine().Split().ToArray();
- int size = Math.Min(words1.Length, words2.Length);
- int length1 = words1.Length;
- int length2 = words2.Length;
- int countLeft = 0, countRight = 0;
- // CHECK LEFT side
- for (int i = 0; i < size; i++)
- {
- if (words1[i]==words2[i])
- {
- countLeft++;
- }
- else
- {
- break;
- }
- }
- // CHECK RIGHT side
- for (int i = 1; i < size; i++)
- {
- if (words1[length1-i]==words2[length2-i])
- {
- countRight++;
- }
- else
- {
- break;
- }
- }
- if (countLeft==0 && countRight==0)
- {
- Console.WriteLine(countLeft);
- }
- else
- {
- Console.WriteLine(Math.Max(countLeft,countRight));
- }
- } // End of Main
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement