Advertisement
martinvalchev

Largest_Common_End

Feb 7th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.24 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace Largest_Common_End
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string[] words1 = Console.ReadLine().Split(' ').ToArray();
  11.             string[] words2 = Console.ReadLine().Split(' ').ToArray();
  12.             int leftCount = 0;
  13.             int rightCount = 0;
  14.  
  15.             for (int i = 0; i < Math.Min(words1.Length, words2.Length); i++)
  16.             {
  17.                 if (words1[i] == words2[i])
  18.                 {
  19.                     leftCount++;
  20.                 }
  21.                 else
  22.                 {
  23.                     break;
  24.                 }
  25.             }
  26.             for (int i = 0; i < Math.Min(words1.Length, words2.Length); i++)
  27.             {
  28.                 if (words1[words1.Length-1-i] == words2[words2.Length - 1 - i])
  29.                 {
  30.                     rightCount++;
  31.                 }
  32.                 else
  33.                 {
  34.                     break;
  35.                 }
  36.             }
  37.             if (leftCount > rightCount)
  38.             {
  39.                 Console.WriteLine(leftCount);
  40.             }
  41.             else
  42.             {
  43.                 Console.WriteLine(rightCount);
  44.             }
  45.             }
  46.         }
  47.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement