bastien.monsarrat 6 years ago
parent
commit
da7549b2fb
5 changed files with 100 additions and 0 deletions
  1. 6 0
      Adv2018.sln
  2. 9 0
      D8.2/D08.2.csproj
  3. 77 0
      D8.2/Program.cs
  4. 8 0
      D8.2/Properties/launchSettings.json
  5. 0 0
      D8.2/input.txt

+ 6 - 0
Adv2018.sln

@@ -35,6 +35,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "D07.2", "D7.2\D07.2.csproj"
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D08.1", "D8.1\D08.1.csproj", "{FF55594F-5EFF-4F7C-9882-34ED5F8E6EE0}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D08.2", "D8.2\D08.2.csproj", "{92230804-D08E-4AB9-9EA3-F3FA233854A3}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -105,6 +107,10 @@ Global
 		{FF55594F-5EFF-4F7C-9882-34ED5F8E6EE0}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{FF55594F-5EFF-4F7C-9882-34ED5F8E6EE0}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{FF55594F-5EFF-4F7C-9882-34ED5F8E6EE0}.Release|Any CPU.Build.0 = Release|Any CPU
+		{92230804-D08E-4AB9-9EA3-F3FA233854A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{92230804-D08E-4AB9-9EA3-F3FA233854A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{92230804-D08E-4AB9-9EA3-F3FA233854A3}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{92230804-D08E-4AB9-9EA3-F3FA233854A3}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 9 - 0
D8.2/D08.2.csproj

@@ -0,0 +1,9 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <TargetFramework>netcoreapp2.1</TargetFramework>
+    <RootNamespace>D8._2</RootNamespace>
+  </PropertyGroup>
+
+</Project>

+ 77 - 0
D8.2/Program.cs

@@ -0,0 +1,77 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+
+namespace D8._2
+{
+    class Program
+    {
+        static void Main(string[] args)
+        {
+            if (args.Length < 1) return;
+            if (File.Exists(args[0]) == false) return;
+            var file = File.OpenText(args[0]);
+
+            var text = file.ReadToEnd();
+            var all = new List<string>(text.Split(" "));
+            
+            var root = getNode(all);
+
+            Console.WriteLine($"Result is : {root.Value}");
+        }
+
+        static Node getNode(List<string> all)
+        {
+            var node = new Node();
+
+            (int children, int metadatas) header = (int.Parse(all[0]), int.Parse(all[1]));
+
+            all.RemoveAt(0);
+            all.RemoveAt(0);
+
+            for (int j = 0; j < header.children; j++)
+            {
+                var childnode = getNode(all);
+                node.Children.Add(childnode);
+            }
+
+            int metasum = 0;
+
+            for (int j = 0; j < header.metadatas; j++)
+            {
+                int meta = int.Parse(all[0]);
+                all.RemoveAt(0);
+                node.Meta.Add(meta);
+
+                if (header.children == 0) metasum += meta;
+                else
+                {
+                    var i = meta - 1;
+                    if (i < 0 || i >= node.Children.Count) continue;
+
+                    metasum += node.Children[i].Value;
+                }
+            }
+
+            node.Value = metasum;
+
+            return node;
+        }
+    }
+
+
+    class Node
+    {
+        public List<int> Meta { get; set; }
+
+        public List<Node> Children { get; set; }
+
+        public int Value { get; set; }
+
+        public Node()
+        {
+            Meta = new List<int>();
+            Children = new List<Node>();
+        }
+    }
+}

+ 8 - 0
D8.2/Properties/launchSettings.json

@@ -0,0 +1,8 @@
+{
+  "profiles": {
+    "D08.2": {
+      "commandName": "Project",
+      "commandLineArgs": "\"D:\\adv\\Adv2018\\D8.2\\input.txt\" "
+    }
+  }
+}

File diff suppressed because it is too large
+ 0 - 0
D8.2/input.txt


Some files were not shown because too many files changed in this diff