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

+ 12 - 0
Adv2015.sln

@@ -43,6 +43,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D10.2", "D10.2\D10.2.csproj
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D11", "D11.1\D11.csproj", "{D4001022-526D-4548-BB09-6F9DFD03B743}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D12.1", "D12.1\D12.1.csproj", "{D6E6034D-6F56-4845-A9C1-D18092C4A8AC}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D12.2", "D12.2\D12.2.csproj", "{DFA340DE-DDF5-4E99-949C-4680B3E8F2F6}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -129,6 +133,14 @@ Global
 		{D4001022-526D-4548-BB09-6F9DFD03B743}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{D4001022-526D-4548-BB09-6F9DFD03B743}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{D4001022-526D-4548-BB09-6F9DFD03B743}.Release|Any CPU.Build.0 = Release|Any CPU
+		{D6E6034D-6F56-4845-A9C1-D18092C4A8AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{D6E6034D-6F56-4845-A9C1-D18092C4A8AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{D6E6034D-6F56-4845-A9C1-D18092C4A8AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{D6E6034D-6F56-4845-A9C1-D18092C4A8AC}.Release|Any CPU.Build.0 = Release|Any CPU
+		{DFA340DE-DDF5-4E99-949C-4680B3E8F2F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{DFA340DE-DDF5-4E99-949C-4680B3E8F2F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{DFA340DE-DDF5-4E99-949C-4680B3E8F2F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{DFA340DE-DDF5-4E99-949C-4680B3E8F2F6}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

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

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

+ 26 - 0
D12.1/Program.cs

@@ -0,0 +1,26 @@
+using System;
+using System.IO;
+using System.Text.RegularExpressions;
+
+namespace D12._1
+{
+    class Program
+    {
+        static void Main(string[] args)
+        {
+            if (args.Length < 1) throw new ArgumentException();
+            if (File.Exists(args[0]) == false) throw new FileNotFoundException();
+
+            var input = File.ReadAllText(args[0]);
+
+            int answer = 0;
+
+            var regex = new Regex(@"(-?\d+)");
+            var matches = regex.Matches(input);
+            foreach (Match match in matches)
+                answer += int.Parse(match.Value);
+
+            Console.WriteLine($"The answer is : {answer}");
+        }
+    }
+}

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

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

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 0 - 0
D12.1/input.txt


+ 13 - 0
D12.2/D12.2.csproj

@@ -0,0 +1,13 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <TargetFramework>netcoreapp2.1</TargetFramework>
+    <RootNamespace>D12._2</RootNamespace>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
+  </ItemGroup>
+
+</Project>

+ 59 - 0
D12.2/Program.cs

@@ -0,0 +1,59 @@
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+using Newtonsoft.Json.Serialization;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Reflection;
+using System.Text.RegularExpressions;
+
+namespace D12._2
+{
+
+    public class PropertyIgnoreSerializerContractResolver : DefaultContractResolver
+    {
+        protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
+        {
+            var property = base.CreateProperty(member, memberSerialization);
+
+            if (property.PropertyName == "red")
+            {
+                property.ShouldSerialize = i => false;
+                property.Ignored = true;
+            }
+
+            return property;
+        }
+    }
+
+    class Program
+    {
+        static void Main(string[] args)
+        {
+            if (args.Length < 1) throw new ArgumentException();
+            if (File.Exists(args[0]) == false) throw new FileNotFoundException();
+
+            var input = File.ReadAllText(args[0]);
+
+            // Use dynamic to skip the use of specialized functions and a factory pattern
+            dynamic n = JsonConvert.DeserializeObject(input);
+
+            var result = SumValues(n);
+
+            Console.WriteLine($"The answer is : {result}");
+        }
+
+        private static long SumValues(JValue n) => n.Type == JTokenType.Integer ? (long) n.Value : 0;
+
+        private static long SumValues(JObject n)
+        {
+            if (n.Properties().Any(p => (p.Value as JValue)?.Value as string == "red"))
+                return 0;
+
+            return n.Properties().Sum((dynamic a) => (long)SumValues(a.Value));
+        }
+
+        private static long SumValues(JArray n) => n.Sum((dynamic a) => (long)SumValues(a));
+    }
+}

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

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

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно