예제 #1
0
        static void Main(string[] args)
        {
            string[] orbits = File.ReadAllLines("./orbits.txt");
            Dictionary <string, orbit_object> toSort = new Dictionary <string, orbit_object>();

            foreach (string item in orbits)
            {
                string[] parameters = item.Split(')');
                toSort[parameters[0]] = new orbit_object(parameters[0]);
                toSort[parameters[1]] = new orbit_object(parameters[1]);
            }

            foreach (string item in orbits)
            {
                string[] parameters = item.Split(')');
                toSort[parameters[0]].addObject(toSort[parameters[1]]);
            }
            Console.WriteLine($"Total number of orbits: {toSort["COM"].getOrbits(0)}");
            var YOU = toSort["COM"].getPathToRoot("YOU");
            var SAN = toSort["COM"].getPathToRoot("SAN");

            YOU.Reverse();
            SAN.Reverse();
            while (YOU[0].Equals(SAN[0]))
            {
                var toRemove = YOU[0];
                YOU.Remove(toRemove);
                SAN.Remove(toRemove);
            }
            var len = YOU.Count + SAN.Count - 2;

            Console.WriteLine($"transfers needed between YOU and SAN: {len}");
            Console.ReadLine();
        }
예제 #2
0
 public void addObject(orbit_object child)
 {
     objects.Add(child);
     child.parent = this;
 }
예제 #3
0
 public orbit_object(string id, orbit_object parent_obj = null)
 {
     self_id = id;
     objects = new List <orbit_object>();
     parent  = parent_obj;
 }