Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. - "1->2"
  2. - "1->2->3"
  3. - "1->2->3->4"
  4. - "5->6"
  5. - "5->6->7"
  6. - "5->6->7->8"
  7.  
  8. "1->2->3->4"
  9. "5->6->7->8"
  10.  
  11. public class Program
  12. {
  13. public static void Main(string[] args)
  14. {
  15. List<(string, i)> flattenedPaths = new List<(string, i)>
  16. {
  17. ("1->2", 0)
  18. ("1->2->3", 1)
  19. ("1->2->3->4", 2)
  20. ("5->6", 3)
  21. ("5->6->7", 4)
  22. ("5->6->7->8", 5)
  23. };
  24.  
  25. IEnumerable<string> uniquePaths = GetUniquePaths(flattenedPaths);
  26. }
  27.  
  28. public static IEnumerable<(string, int)> GetUniquePaths(List<(string, int)> Paths)
  29. {
  30. for (int i = 0; i < Paths.Count; i++)
  31. {
  32. bool doesMatchContain = Paths.Skip(i)
  33. .Any(x => x.Item1.Contains(Paths[i].Item1));
  34.  
  35. if (!doesMatchContain)
  36. yield return Paths[i];
  37. }
  38. }
  39. }
  40.  
  41. using System;
  42. using System.Collections.Generic;
  43. using System.Linq;
  44.  
  45. public class Program
  46. {
  47. public static void Main()
  48. {
  49. Console.WriteLine(string.Join("rn", uniquePaths.Select(z => z.Item1 + " " + z.Item2)));
  50. Console.WriteLine("Done");
  51. Console.ReadLine();
  52. }
  53.  
  54. private static List<(string, int)> flattenedPaths = new List<(string, int)>
  55. {
  56. ("1->2", 0),
  57. ("1->2->3", 1),
  58. ("1->2->3->4", 2),
  59. ("5->6", 3),
  60. ("5->6->7", 4),
  61. ("5->6->7->8", 5),
  62. };
  63.  
  64. private static IEnumerable<(string, int)> uniquePaths = GetUniquePaths(flattenedPaths);
  65.  
  66. private static IEnumerable<(string, int)> GetUniquePaths(List<(string, int)> Paths)
  67. {
  68. var betterData = Paths
  69. .Select(z => new
  70. {
  71. Number = z.Item2,
  72. Value = z.Item1,
  73. Lower = int.Parse(z.Item1.Substring(0, z.Item1.IndexOf("-"))),
  74. Upper = int.Parse(z.Item1.Substring(z.Item1.LastIndexOf("-") + 2))
  75. })
  76. .OrderByDescending(z => z.Value.Length).ThenByDescending(z => z.Upper).ThenBy(z => z.Lower).ToList();
  77.  
  78. foreach (var entry in betterData.ToList())
  79. {
  80. betterData.RemoveAll(z => z != entry && z.Lower >= entry.Lower && z.Upper <= entry.Upper);
  81. }
  82.  
  83. return betterData.Select(x => (x.Value, x.Number));
  84. }
  85. }
  86.  
  87. class Program
  88. {
  89. string output;
  90. public void initalize(string findlongestcontainof)
  91. {
  92. int length = 0;
  93.  
  94. List<string> inputs = new List<string>();
  95. inputs.Add("1->2->3");
  96. inputs.Add("1->2->3->4");
  97. inputs.Add("1->2->3->4->5->6");
  98. inputs.Add("1->2->3->4->5");
  99.  
  100. foreach(string s in inputs)
  101. {
  102. if(s.Contains(findlongestcontainof))
  103. {
  104. if(s.Length > length)
  105. {
  106. length = s.Length;
  107. output = s;
  108. }
  109. }
  110. }
  111. }
  112. static void Main(string[] args)
  113. {
  114. Program p = new Program();
  115. p.initalize("1->2");
  116. Console.WriteLine(p.output);
  117. Console.ReadLine();
  118. }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement