Пример #1
0
        public void JsonSerialize()
        {
            var input = new laba1.Input
            {
                K    = 35,
                Sums = new[] { 1m, 2m, 3.5m, 4.8m, 9.999m, 99m },
                Muls = new[] { 1, 2, 34, 42, 34, 41243 },
            };
            var serialize        = new laba1.JsonSerializator();
            var serializedObject = serialize.Serialize(input);

            Assert.AreEqual(serializedObject,
                            "{\"K\":35,\"Sums\":[1,2,3.5,4.8,9.999,99],\"Muls\":[1,2,34,42,34,41243]}");
        }
Пример #2
0
        static void Main(string[] args)
        {
            var port       = Console.ReadLine();
            var httpClient = new HttpClient();
            var url        = $"http://127.0.0.1:{port}";

            while (!httpClient.Ping(url))
            {
                ;
            }

            var serializer = new JsonSerializator();
            var input      = serializer.Deserialize <Input>(httpClient.GetInputData(url));

            decimal sumResult    = 0;
            var     sortedInputs = new List <decimal>();

            foreach (var term in input.Sums)
            {
                sumResult += term;
                sortedInputs.Add(term);
            }
            sumResult *= input.K;
            var mulResult = 1;

            foreach (var multiplier in input.Muls)
            {
                mulResult *= multiplier;
                sortedInputs.Add(multiplier);
            }
            sortedInputs.Sort();
            var output = new Output
            {
                SumResult    = sumResult,
                MulResult    = mulResult,
                SortedInputs = sortedInputs.ToArray(),
            };

            httpClient.WriteAnswer(url, AddZeros(serializer.Serialize(output)));
        }