VelizarAvramov

01. Largest Common End

Nov 25th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.84 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _01._Largest_Common_End
  4. {
  5.     class LargestCommonEnd
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string[] firstArr = Console.ReadLine().Split();
  10.             string[] secondArr = Console.ReadLine().Split();
  11.  
  12.             int shorter = Math.Min(firstArr.Length, secondArr.Length);
  13.             int leftCount = 0;
  14.             int rigthCount = 0;
  15.  
  16.             for (int i = 0; i < shorter; i++)
  17.             {
  18.                 if (firstArr[i] == secondArr[i])
  19.                 {
  20.                     leftCount++;
  21.                 }
  22.                 if (firstArr[firstArr.Length - 1 - i] == secondArr[secondArr.Length - 1 - i])
  23.                 {
  24.                     rigthCount++;
  25.                 }
  26.             }
  27.             Console.WriteLine(Math.Max(leftCount, rigthCount));
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment