Advertisement
bacco

Largest Common End (with Method)

Jun 2nd, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. using System;
  2.  
  3. namespace test1
  4. {
  5.     class MainClass
  6.     {
  7.         public static void Main(string[] args)
  8.         {
  9.             string[] arrOne = Console.ReadLine().Split();
  10.             string[] arrTwo = Console.ReadLine().Split();
  11.  
  12.             var countLeft  = 0;
  13.             var countRight = 0;
  14.             int avarage = Math.Min(arrOne.Length, arrTwo.Length);
  15.  
  16.             countLeft = ReturnCount(avarage, countLeft, arrOne, arrTwo);
  17.  
  18.             Array.Reverse(arrOne);
  19.             Array.Reverse(arrTwo);
  20.  
  21.             countRight = ReturnCount(avarage, countRight, arrOne, arrTwo);
  22.  
  23.             Console.WriteLine(Math.Max(countLeft, countRight));
  24.         }
  25.  
  26.         static int ReturnCount(int avarage, int count , string[] arrOne, string[] arrTwo)
  27.         {
  28.             for (int i = 0; i < avarage; i++)
  29.             {
  30.                 if (arrOne[i] == arrTwo[i])
  31.                 {
  32.                     count++;
  33.                 }
  34.             }
  35.             return count;
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement