Advertisement
Guest User

Untitled

a guest
Mar 7th, 2018
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Wintellect.PowerCollections;
  5.  
  6.  
  7. namespace TestGround
  8. {
  9. class Program
  10. {
  11.  
  12. public static void Main()
  13. {
  14. string[] arr = Console.ReadLine().Split(' ');
  15. string[] arr2 = Console.ReadLine().Split(' ');
  16.  
  17. int countFront = CountFront(arr, arr2);
  18. int countBack = CountBack(arr, arr2);
  19.  
  20. Console.WriteLine(Math.Max(countFront, countBack));
  21. }
  22.  
  23. private static int CountFront(string[] arr, string[] arr2)
  24. {
  25. int counter = 0;
  26. for (int i = 0; i < Math.Min(arr.Length, arr2.Length); i++)
  27. {
  28. if (arr[i] == arr2[i])
  29. {
  30. counter++;
  31. }
  32. else
  33. {
  34. break;
  35. }
  36. }
  37. return counter;
  38. }
  39.  
  40. private static int CountBack(string[] arr, string[] arr2)
  41. {
  42. string[] bigger;
  43. string[] smaller;
  44. if (arr.Length >= arr2.Length)
  45. {
  46. bigger = arr;
  47. smaller = arr2;
  48. }
  49. else
  50. {
  51. bigger = arr2;
  52. smaller = arr;
  53. }
  54. int sizeDifference = bigger.Length - smaller.Length;
  55. int counter = 0;
  56. for (int i = bigger.Length - 1; i >= sizeDifference; i--)
  57. {
  58. if (bigger[i] == smaller[i - sizeDifference])
  59. {
  60. counter++;
  61. }
  62. else
  63. {
  64. break;
  65. }
  66. }
  67. return counter;
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement