bastien.monsarrat 6 жил өмнө
parent
commit
b7d28d5810

+ 12 - 0
Adv2016.sln

@@ -63,6 +63,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D17.2", "D17.2\D17.2.csproj
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D18", "D18.1\D18.csproj", "{ABDF44A3-B648-41A0-9A17-356743AE264B}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D19.1", "D19.1\D19.1.csproj", "{A0E22EE7-3971-41CB-8241-A812D265AE84}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D19.2", "D19.2\D19.2.csproj", "{73D904FB-3A54-429F-8858-DCD1BC871F51}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -189,6 +193,14 @@ Global
 		{ABDF44A3-B648-41A0-9A17-356743AE264B}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{ABDF44A3-B648-41A0-9A17-356743AE264B}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{ABDF44A3-B648-41A0-9A17-356743AE264B}.Release|Any CPU.Build.0 = Release|Any CPU
+		{A0E22EE7-3971-41CB-8241-A812D265AE84}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{A0E22EE7-3971-41CB-8241-A812D265AE84}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{A0E22EE7-3971-41CB-8241-A812D265AE84}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{A0E22EE7-3971-41CB-8241-A812D265AE84}.Release|Any CPU.Build.0 = Release|Any CPU
+		{73D904FB-3A54-429F-8858-DCD1BC871F51}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{73D904FB-3A54-429F-8858-DCD1BC871F51}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{73D904FB-3A54-429F-8858-DCD1BC871F51}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{73D904FB-3A54-429F-8858-DCD1BC871F51}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

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

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

+ 42 - 0
D19.1/Program.cs

@@ -0,0 +1,42 @@
+using System;
+using System.Collections;
+
+namespace D19._1
+{
+    class Program
+    {
+        static void Main(string[] args)
+        {
+            var ba = new BitArray(int.Parse(args[0]), true);
+            int n = ba.Length;
+
+            int i = 0;
+            while (n > 1)
+            {
+                i++;
+                if (i >= ba.Length) i -= ba.Length;
+                while (!ba[i])
+                {
+                    i++;
+                    if (i >= ba.Length) i -= ba.Length;
+                }
+                ba.Set(i, false);
+                n--;
+                while (!ba[i])
+                {
+                    i++;
+                    if (i >= ba.Length) i -= ba.Length;
+                }
+            }
+
+            for (var j = 0; j < ba.Length; j++)
+            {
+                if (ba.Get(j))
+                {
+                    Console.WriteLine($"The answer is : {j+1}");
+                    break;
+                }
+            }
+        }
+    }
+}

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

@@ -0,0 +1,8 @@
+{
+  "profiles": {
+    "D19.1": {
+      "commandName": "Project",
+      "commandLineArgs": "3012210"
+    }
+  }
+}

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

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

+ 31 - 0
D19.2/Program.cs

@@ -0,0 +1,31 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace D19._2
+{
+    class Program
+    {
+        static void Main(string[] args)
+        {
+            var ba = new List<int>();
+
+            for (var j = 1; j <= int.Parse(args[0]); ++j) ba.Add(j);
+
+            int i = 0;
+            while (ba.Count > 1)
+            {
+                var target = i + ba.Count / 2;
+                if (target >= ba.Count) target -= ba.Count;
+
+                ba.RemoveAt(target);
+
+                if (target > i) i++;
+                if (i >= ba.Count) i -= ba.Count;
+            }
+
+            Console.WriteLine($"The answer is : {ba.First()}");
+        }
+    }
+}

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

@@ -0,0 +1,8 @@
+{
+  "profiles": {
+    "D19.2": {
+      "commandName": "Project",
+      "commandLineArgs": "3012210"
+    }
+  }
+}