Advertisement
bacco

Largest Common End

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