Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - "1->2"
- - "1->2->3"
- - "1->2->3->4"
- - "5->6"
- - "5->6->7"
- - "5->6->7->8"
- "1->2->3->4"
- "5->6->7->8"
- public class Program
- {
- public static void Main(string[] args)
- {
- List<(string, i)> flattenedPaths = new List<(string, i)>
- {
- ("1->2", 0)
- ("1->2->3", 1)
- ("1->2->3->4", 2)
- ("5->6", 3)
- ("5->6->7", 4)
- ("5->6->7->8", 5)
- };
- IEnumerable<string> uniquePaths = GetUniquePaths(flattenedPaths);
- }
- public static IEnumerable<(string, int)> GetUniquePaths(List<(string, int)> Paths)
- {
- for (int i = 0; i < Paths.Count; i++)
- {
- bool doesMatchContain = Paths.Skip(i)
- .Any(x => x.Item1.Contains(Paths[i].Item1));
- if (!doesMatchContain)
- yield return Paths[i];
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- public class Program
- {
- public static void Main()
- {
- Console.WriteLine(string.Join("rn", uniquePaths.Select(z => z.Item1 + " " + z.Item2)));
- Console.WriteLine("Done");
- Console.ReadLine();
- }
- private static List<(string, int)> flattenedPaths = new List<(string, int)>
- {
- ("1->2", 0),
- ("1->2->3", 1),
- ("1->2->3->4", 2),
- ("5->6", 3),
- ("5->6->7", 4),
- ("5->6->7->8", 5),
- };
- private static IEnumerable<(string, int)> uniquePaths = GetUniquePaths(flattenedPaths);
- private static IEnumerable<(string, int)> GetUniquePaths(List<(string, int)> Paths)
- {
- var betterData = Paths
- .Select(z => new
- {
- Number = z.Item2,
- Value = z.Item1,
- Lower = int.Parse(z.Item1.Substring(0, z.Item1.IndexOf("-"))),
- Upper = int.Parse(z.Item1.Substring(z.Item1.LastIndexOf("-") + 2))
- })
- .OrderByDescending(z => z.Value.Length).ThenByDescending(z => z.Upper).ThenBy(z => z.Lower).ToList();
- foreach (var entry in betterData.ToList())
- {
- betterData.RemoveAll(z => z != entry && z.Lower >= entry.Lower && z.Upper <= entry.Upper);
- }
- return betterData.Select(x => (x.Value, x.Number));
- }
- }
- class Program
- {
- string output;
- public void initalize(string findlongestcontainof)
- {
- int length = 0;
- List<string> inputs = new List<string>();
- inputs.Add("1->2->3");
- inputs.Add("1->2->3->4");
- inputs.Add("1->2->3->4->5->6");
- inputs.Add("1->2->3->4->5");
- foreach(string s in inputs)
- {
- if(s.Contains(findlongestcontainof))
- {
- if(s.Length > length)
- {
- length = s.Length;
- output = s;
- }
- }
- }
- }
- static void Main(string[] args)
- {
- Program p = new Program();
- p.initalize("1->2");
- Console.WriteLine(p.output);
- Console.ReadLine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement