Exemplo n.º 1
0
        private static LicenseNode CreateTree(Stack <string> lF)
        {
            LicenseNode node = new LicenseNode();

            int nrChilds = int.Parse(lF.Pop());
            int nrMdatas = int.Parse(lF.Pop());

            for (int i = 0; i < nrChilds; i++)
            {
                node.Nodes.Add(CreateTree(lF));
            }

            for (int i = 0; i < nrMdatas; i++)
            {
                int mData = int.Parse(lF.Pop());
                node.MetaData.Add(mData);
                sumMdate += mData;
            }

            return(node);
        }
Exemplo n.º 2
0
        private static LicenseNode CalcNodeValue(LicenseNode node)
        {
            if (node.Nodes.Count == 0)
            {
                foreach (int mdata in node.MetaData)
                {
                    nodeVal += mdata;
                }
            }
            else
            {
                foreach (int childIdx in node.MetaData)
                {
                    if (node.Nodes.Count < childIdx)
                    {
                        continue;
                    }
                    CalcNodeValue(node.Nodes[childIdx - 1]);
                }
            }

            return(node);
        }
Exemplo n.º 3
0
        public static LicenseNode Task1()
        {
            string         input       = "";
            Stack <string> licenseFile = new Stack <string>();

            using (StreamReader reader = new StreamReader(inputPath))
            {
                input = reader.ReadToEnd();
            }

            string[] nums = input.Split(' ');

            for (int i = nums.Length - 1; i >= 0; i--)
            {
                licenseFile.Push(nums[i]);
            }

            LicenseNode root = CreateTree(licenseFile);

            Console.WriteLine(sumMdate);

            return(root);
        }
Exemplo n.º 4
0
        public static void Task2(LicenseNode root)
        {
            CalcNodeValue(root);

            Console.WriteLine(nodeVal);
        }