bastien.monsarrat 6 年之前
父節點
當前提交
60d34975f3
共有 9 個文件被更改,包括 139 次插入13 次删除
  1. 7 1
      Adv2016.sln
  2. 0 12
      Adv2016/Program.cs
  3. 0 0
      D01.1/D01.1.csproj
  4. 40 0
      D01.1/Program.cs
  5. 8 0
      D01.1/Properties/launchSettings.json
  6. 1 0
      D01.1/input.txt
  7. 9 0
      D1.2/D01.2.csproj
  8. 66 0
      D1.2/Program.cs
  9. 8 0
      D1.2/Properties/launchSettings.json

+ 7 - 1
Adv2016.sln

@@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
 # Visual Studio 15
 VisualStudioVersion = 15.0.28307.421
 MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Adv2016", "Adv2016\Adv2016.csproj", "{BFC32D85-5E89-4365-B038-01A75BDB8B94}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "D01.1", "D01.1\D01.1.csproj", "{BFC32D85-5E89-4365-B038-01A75BDB8B94}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D01.2", "D1.2\D01.2.csproj", "{81477827-852E-4DB6-9D2B-C914B9B1B847}"
 EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -15,6 +17,10 @@ Global
 		{BFC32D85-5E89-4365-B038-01A75BDB8B94}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{BFC32D85-5E89-4365-B038-01A75BDB8B94}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{BFC32D85-5E89-4365-B038-01A75BDB8B94}.Release|Any CPU.Build.0 = Release|Any CPU
+		{81477827-852E-4DB6-9D2B-C914B9B1B847}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{81477827-852E-4DB6-9D2B-C914B9B1B847}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{81477827-852E-4DB6-9D2B-C914B9B1B847}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{81477827-852E-4DB6-9D2B-C914B9B1B847}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 0 - 12
Adv2016/Program.cs

@@ -1,12 +0,0 @@
-using System;
-
-namespace Adv2016
-{
-    class Program
-    {
-        static void Main(string[] args)
-        {
-            Console.WriteLine("Hello World!");
-        }
-    }
-}

+ 0 - 0
Adv2016/Adv2016.csproj → D01.1/D01.1.csproj


+ 40 - 0
D01.1/Program.cs

@@ -0,0 +1,40 @@
+using System;
+using System.IO;
+
+namespace D01._1
+{
+    class Program
+    {
+        static void Main(string[] args)
+        {
+            if (args.Length < 1) throw new ArgumentException();
+            if (File.Exists(args[0]) == false) throw new FileNotFoundException();
+
+            string input = File.ReadAllText(args[0]);
+            (int x, int y, int r) coord = (0, 0, 0);
+            foreach (var i in input.Split(", "))
+            {
+                int n = int.Parse(i.Substring(1));
+                switch (i[0])
+                {
+                    case 'R': coord.r += 90; break;
+                    case 'L': coord.r -= 90; break;
+                }
+
+                if (coord.r < 0) coord.r += 360;
+                if (coord.r >= 360) coord.r -= 360;
+
+                switch (coord.r)
+                {
+                    case 0: coord.y -= n; break;
+                    case 90: coord.x += n; break;
+                    case 180: coord.y += n; break;
+                    case 270: coord.x -= n; break;
+                }
+            }
+
+            var manhattan = Math.Abs(coord.x) + Math.Abs(coord.y);
+            Console.WriteLine($"Distance is : {manhattan}");
+        }
+    }
+}

+ 8 - 0
D01.1/Properties/launchSettings.json

@@ -0,0 +1,8 @@
+{
+  "profiles": {
+    "D01.1": {
+      "commandName": "Project",
+      "commandLineArgs": "\"..\\..\\..\\..\\D01.1\\input.txt\""
+    }
+  }
+}

+ 1 - 0
D01.1/input.txt

@@ -0,0 +1 @@
+L2, L3, L3, L4, R1, R2, L3, R3, R3, L1, L3, R2, R3, L3, R4, R3, R3, L1, L4, R4, L2, R5, R1, L5, R1, R3, L5, R2, L2, R2, R1, L1, L3, L3, R4, R5, R4, L1, L189, L2, R2, L5, R5, R45, L3, R4, R77, L1, R1, R194, R2, L5, L3, L2, L1, R5, L3, L3, L5, L5, L5, R2, L1, L2, L3, R2, R5, R4, L2, R3, R5, L2, L2, R3, L3, L2, L1, L3, R5, R4, R3, R2, L1, R2, L5, R4, L5, L4, R4, L2, R5, L3, L2, R4, L1, L2, R2, R3, L2, L5, R1, R1, R3, R4, R1, R2, R4, R5, L3, L5, L3, L3, R5, R4, R1, L3, R1, L3, R3, R3, R3, L1, R3, R4, L5, L3, L1, L5, L4, R4, R1, L4, R3, R3, R5, R4, R3, R3, L1, L2, R1, L4, L4, L3, L4, L3, L5, R2, R4, L2

+ 9 - 0
D1.2/D01.2.csproj

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

+ 66 - 0
D1.2/Program.cs

@@ -0,0 +1,66 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+
+namespace D01._2
+{
+    class Program
+    {
+        static void Main(string[] args)
+        {
+            if (args.Length < 1) throw new ArgumentException();
+            if (File.Exists(args[0]) == false) throw new FileNotFoundException();
+
+            string input = File.ReadAllText(args[0]);
+
+            var visited = new HashSet<(int, int)>()
+            {
+                (0, 0)
+            };
+
+            (int x, int y, int r) coord = (0, 0, 0);
+            foreach (var i in input.Split(", "))
+            {
+                int n = int.Parse(i.Substring(1));
+                switch (i[0])
+                {
+                    case 'R': coord.r += 90; break;
+                    case 'L': coord.r -= 90; break;
+                }
+
+                if (coord.r < 0) coord.r += 360;
+                if (coord.r >= 360) coord.r -= 360;
+
+                if (Visit(ref coord, n, visited) == false)
+                    break;
+            }
+
+            var manhattan = Math.Abs(coord.x) + Math.Abs(coord.y);
+            Console.WriteLine($"Distance is : {manhattan}");
+        }
+
+        private static bool Visit(ref (int x, int y, int r) coord, int n, HashSet<(int, int)> visited)
+        {
+            for (var i = 0; i < n; ++i)
+            {
+                switch (coord.r)
+                {
+                    case 0: coord.y --; break;
+                    case 90: coord.x ++; break;
+                    case 180: coord.y ++; break;
+                    case 270: coord.x --; break;
+                }
+
+                if (visited.Add((coord.x, coord.y)) == false)
+                    return false;
+            }
+
+            return true;
+        }
+
+        private static void HashSet(int v1, object x, int v2, object y, int v3, object r)
+        {
+            throw new NotImplementedException();
+        }
+    }
+}

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

@@ -0,0 +1,8 @@
+{
+  "profiles": {
+    "D01.2": {
+      "commandName": "Project",
+      "commandLineArgs": "\"..\\..\\..\\..\\D01.1\\input.txt\""
+    }
+  }
+}