bastien.monsarrat 6 vuotta sitten
vanhempi
commit
b1d4d43d39

+ 12 - 0
Adv2016.sln

@@ -33,6 +33,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D07.2", "D07.2\D07.2.csproj
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D08", "D08.1\D08.csproj", "{F9878C0B-C390-457F-AB83-4E59494BE9FD}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D09.1", "D09.1\D09.1.csproj", "{C0247F63-D60A-44B9-8682-7D9616738528}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D09.2", "D09.2\D09.2.csproj", "{9731BDDB-A87A-4B78-9171-7D853CD457BE}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -99,6 +103,14 @@ Global
 		{F9878C0B-C390-457F-AB83-4E59494BE9FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{F9878C0B-C390-457F-AB83-4E59494BE9FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{F9878C0B-C390-457F-AB83-4E59494BE9FD}.Release|Any CPU.Build.0 = Release|Any CPU
+		{C0247F63-D60A-44B9-8682-7D9616738528}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{C0247F63-D60A-44B9-8682-7D9616738528}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{C0247F63-D60A-44B9-8682-7D9616738528}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{C0247F63-D60A-44B9-8682-7D9616738528}.Release|Any CPU.Build.0 = Release|Any CPU
+		{9731BDDB-A87A-4B78-9171-7D853CD457BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{9731BDDB-A87A-4B78-9171-7D853CD457BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{9731BDDB-A87A-4B78-9171-7D853CD457BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{9731BDDB-A87A-4B78-9171-7D853CD457BE}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 9 - 0
D09.1/D09.1.csproj

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

+ 57 - 0
D09.1/Program.cs

@@ -0,0 +1,57 @@
+using System;
+using System.IO;
+
+namespace D09._1
+{
+    class Program
+    {
+
+        static bool TryGetToken(string input, ref int index, out int length, out int repetition)
+        {
+            length = 0;
+            repetition = 0;
+            int idx = index;
+
+            if (input[idx++] != '(') return false;
+
+            int nindex = idx;
+            while (input[idx] >= '0' && input[idx] <= '9') idx++;
+
+            length = int.Parse(input.Substring(nindex, idx - nindex));
+            if (input[idx++] != 'x') return false;
+
+            nindex = idx;
+            while (input[idx] >= '0' && input[idx] <= '9') idx++;
+
+            repetition = int.Parse(input.Substring(nindex, idx - nindex));
+
+            if (input[idx++] != ')') return false;
+
+            idx += length;
+            index = idx - 1;
+            length *= repetition;
+
+            return true;
+        }
+
+        static void Main(string[] args)
+        {
+            if (args.Length < 1) throw new ArgumentException();
+            if (File.Exists(args[0]) == false) throw new FileNotFoundException();
+
+            int totalLength = 0;
+
+            var text = File.ReadAllText(args[0]);
+            for (var i = 0; i < text.Length; ++i)
+            {
+                if (text[i] == ' ' || text[i] == '\n' || text[i] == '\t') continue;
+
+                if (TryGetToken(text, ref i, out int length, out int repetition))
+                    totalLength += length;
+                else totalLength++;
+            }
+
+            Console.WriteLine(totalLength);
+        }
+    }
+}

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

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

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 0 - 0
D09.1/input.txt


+ 9 - 0
D09.2/D09.2.csproj

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

+ 76 - 0
D09.2/Program.cs

@@ -0,0 +1,76 @@
+using System;
+using System.IO;
+
+namespace D09._2
+{
+    class Program
+    {
+
+        static bool TryGetToken(string input, ref int index, out long length)
+        {
+            length = 0;
+            int idx = index;
+
+            if (IsCompressionToken(input, out int strlen, out int repetition, ref idx) == false)
+                return false;
+
+            long sublength = 0;
+            for (var i = idx; i < idx + strlen; i++)
+            {
+                if (TryGetToken(input, ref i, out long len))
+                    sublength += len;
+                else sublength++;
+            }
+
+            idx += strlen;
+            index = idx - 1;
+
+            length = sublength * repetition;
+
+            return true;
+        }
+
+        private static bool IsCompressionToken(string input, out int strlen, out int repetition, ref int idx)
+        {
+            strlen = 0;
+            repetition = 0;
+
+            if (input[idx++] != '(') return false;
+
+            int nindex = idx;
+            while (input[idx] >= '0' && input[idx] <= '9') idx++;
+
+            strlen = int.Parse(input.Substring(nindex, idx - nindex));
+            if (input[idx++] != 'x') return false;
+
+            nindex = idx;
+            while (input[idx] >= '0' && input[idx] <= '9') idx++;
+
+            repetition = int.Parse(input.Substring(nindex, idx - nindex));
+
+            if (input[idx++] != ')') return false;
+
+            return true;
+        }
+
+        static void Main(string[] args)
+        {
+            if (args.Length < 1) throw new ArgumentException();
+            if (File.Exists(args[0]) == false) throw new FileNotFoundException();
+
+            long totalLength = 0;
+
+            var text = File.ReadAllText(args[0]);
+            for (var i = 0; i < text.Length; ++i)
+            {
+                if (text[i] == ' ' || text[i] == '\n' || text[i] == '\t') continue;
+
+                if (TryGetToken(text, ref i, out long length))
+                    totalLength += length;
+                else totalLength++;
+            }
+
+            Console.WriteLine(totalLength);
+        }
+    }
+}

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

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

Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä