Advertisement
Guest User

Arrays==HELL!

a guest
Oct 8th, 2017
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. class LargestCommonEnd
  5. {
  6. static void Main(string[] args)
  7. {
  8. string[] arr = Console.ReadLine()
  9. .Split(new char[] {' '},
  10. StringSplitOptions.
  11. RemoveEmptyEntries);
  12. string[] arr2 = Console.ReadLine()
  13. .Split(new char[] {' '},
  14. StringSplitOptions.
  15. RemoveEmptyEntries);
  16. int LeftCount = CommonMaxEnd(arr,arr2);
  17. Array.Reverse(arr);
  18. arr2 = arr2.Reverse().ToArray();
  19. int RightCount = CommonMaxEnd(arr, arr2);
  20. Console.WriteLine($"{Math.Max(LeftCount,RightCount)}");
  21.  
  22. }
  23. private static int CommonMaxEnd(string[] arr, string[] arr2)
  24. {
  25. int Similar = Math.Min(arr.Length, arr2.Length);
  26. int count = 0;
  27. for (int i = 0; i < Similar; i++)
  28. {
  29. if (arr[i] == arr2[i])
  30. {
  31. count++;
  32. Console.WriteLine(count);
  33. }
  34. else
  35. {
  36. break;
  37. }
  38. }
  39. return count;
  40.  
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement