Beispiel #1
0
        private static void Main()
        {
            Helper.ConsoleMio.Setup();

            Helper.ConsoleMio.PrintHeading("Task 3 Sort a Sequence in Increasing Order");

            List <int> sequence = Helper.ReadCollection(0, new[] { ' ' }).ToList();

            Helper.ConsoleMio.WriteLine("Sorting with heapsort...", DarkBlue);
            HeapSort(sequence, sequence.Count);

            Helper.ConsoleMio.WriteLine(
                $"Result: {string.Join(" ", sequence)}",
                DarkGreen);
        }
Beispiel #2
0
        private static void Main()
        {
            Helper.ConsoleMio.Setup();

            Helper.ConsoleMio.PrintHeading("Task 1 Sum And Average Of A Sequence");

            uint[] sequence = Helper.ReadCollection(
                template: (uint)0,
                splitChars: new char[] { ' ' })
                              .ToArray();

            Helper.ConsoleMio.Write("Sum: ", DarkGreen);
            uint sum = SequenceSum(sequence);

            Console.WriteLine(sum);

            Helper.ConsoleMio.Write("Average: ", DarkGreen);
            Console.WriteLine(sum / (double)sequence.Length);
        }
        private static void Main()
        {
            Helper.ConsoleMio.Setup();

            Helper.ConsoleMio.PrintHeading("Task 2 Reverse a Sequence Using a Stack");

            int[] collection = Helper.ReadCollection(0, new char[] { ' ' }).ToArray();

            Stack <int> stack = new Stack <int>(collection);

            int[] reversed = new int[collection.Length];

            for (int i = 0; i < reversed.Length; i++)
            {
                reversed[i] = stack.Pop();
            }

            Helper.ConsoleMio.WriteLine(
                $"Result: { string.Join(" ", reversed)}",
                DarkGreen);
        }
Beispiel #4
0
        public static void Main()
        {
            helper.ConsoleMio.Setup();
            helper.ConsoleMio.PrintHeading("Task 1 Count Double Occurrence");

            ICollection <double> collection = helper.ReadCollection(template: 0.1, splitChars: null);

            Dictionary <double, int> doubleOccurenceMap =
                CommonMethods.CreateOccurrenceMap(collection);

            Console.WriteLine("{0,-10} -> value", "key");
            foreach (double key in doubleOccurenceMap.Keys)
            {
                helper.ConsoleMio.Write("{0,-10:F4} -> ", ConsoleColor.DarkGreen, key);
                helper.ConsoleMio.WriteLine(
                    "{0} {1}",
                    ConsoleColor.DarkCyan,
                    doubleOccurenceMap[key],
                    doubleOccurenceMap[key] == 1 ? "time" : "times");
            }
        }
        private static void Main()
        {
            Helper.ConsoleMio.Setup();

            Helper.ConsoleMio.PrintHeading("Task 5 Remove All Negative Numbers From a Sequence");

            List <int> collection = Helper.ReadCollection(0, null).ToList();

            List <int> positiveCollection = new List <int>(collection.Count);

            foreach (int i in collection)
            {
                if (i >= 0)
                {
                    positiveCollection.Add(i);
                }
            }

            Helper.ConsoleMio.WriteLine(
                $"Result: {string.Join(" ", positiveCollection)}", DarkGreen);
        }
        private static void Main()
        {
            Helper.ConsoleMio.Setup();

            Helper.ConsoleMio.PrintHeading("Task 4 Longest Subsequence of Equal Elements");

            ConsoleKey choice;

            do
            {
                Console.Write("Run the test or use user input(Y/N): ");
                choice = Console.ReadKey(true).Key;
                Console.WriteLine();
            }while (choice != ConsoleKey.Y && choice != ConsoleKey.N);

            if (choice == ConsoleKey.N)
            {
                List <int> sequence = Helper.ReadCollection(0, null).ToList();

                List <int> subSequenceOfEqueal = GetLongestSubsequenceOfEqualElements(sequence);

                int size = subSequenceOfEqueal.Count;

                var collectionAsString = string.Join(" ", subSequenceOfEqueal);
                var pluralForm         = size == 1 ? string.Empty : "s";

                Helper.ConsoleMio.WriteLine(
                    $"Result: {size} repeating element{pluralForm} \nCollection: {collectionAsString}",
                    DarkGreen);
            }
            else
            {
                bool result = TestTheThing(GetLongestSubsequenceOfEqualElements);
                if (result)
                {
                    Helper.ConsoleMio.WriteLine(
                        "Test is successfull! What did you expected...", Green);
                }
            }
        }
        private static void Main()
        {
            Helper.ConsoleMio.Setup();

            Helper.ConsoleMio.PrintHeading("Task 6 Remove Elements That Occur Odd Number Of Times ");

            ICollection <int> collection = Helper.ReadCollection(0, new[] { ' ', ',' });

            Dictionary <int, int> occurrencesMap = MapByElementOccurrence(collection);

            var filteredCollection = new List <int>();

            foreach (int number in collection)
            {
                if (occurrencesMap[number] % 2 == 0)
                {
                    filteredCollection.Add(number);
                }
            }

            Helper.ConsoleMio.WriteLine(
                $"Result: {string.Join(" ", filteredCollection)}", DarkGreen);
        }