NedyalkoKikov

LargetCommonEnd

May 30th, 2016
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace LargestCommonEnd
  8. {
  9. class LargeCommonEnd
  10. {
  11. static void Main()
  12. {
  13. string[] firstArr = Console.ReadLine().Split();
  14. string[] secondArr = Console.ReadLine().Split();
  15. int smallerArr = Math.Min(firstArr.Length, secondArr.Length);
  16.  
  17. int leftCounter = CheckArrays(firstArr, secondArr, smallerArr);
  18. Array.Reverse(firstArr);
  19. Array.Reverse(secondArr);
  20. int rightCounter = CheckArrays(firstArr, secondArr, smallerArr);
  21. Console.WriteLine(Math.Max(leftCounter,rightCounter));
  22. }
  23.  
  24. public static int CheckArrays(string[] firstArr, string[] secondArr, int smallerArr)
  25. {
  26. int counter = 0;
  27. for (int i = 0; i < smallerArr; i++)
  28. {
  29. if (firstArr[i] == secondArr[i])
  30. {
  31. counter++;
  32. }
  33. else
  34. {
  35. break;
  36. }
  37. }
  38.  
  39. return counter;
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment