Advertisement
NedyalkoKikov

largestCommonEndV2

Jun 6th, 2016
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 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 LargestCommonEndv2
  8. {
  9. class Program
  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. int leftCorner = 0;
  17. int rightCorner = 0;
  18. for (int left = 0; left < smallerArr; left++)
  19. {
  20. if (firstArr[left] == secondArr[left])
  21. {
  22. leftCorner++;
  23. }
  24. else
  25. {
  26. break;
  27. }
  28. }
  29. Array.Reverse(firstArr);
  30. Array.Reverse(secondArr);
  31. for (int right = 0; right < smallerArr; right++)
  32. {
  33. if (secondArr[right] == firstArr[right])
  34. {
  35. rightCorner++;
  36. }
  37. else
  38. {
  39. break;
  40. }
  41. }
  42. Console.WriteLine(Math.Max(leftCorner, rightCorner));
  43. }
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement