コード例 #1
0
        // Write a program that reads N integers from the console and reverses them using a stack.
        // Use the Stack<int> class.
        public static void Main(string[] args)
        {
            SequenceParser.WarningMessage();
            Console.WriteLine("Task 2 : Enter Interegers (like: '1 2 3' or '1,2,3') to stack and reverse");

            var digits = SequenceParser.StringNumberSequenceToList(Console.ReadLine());

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

            foreach (var item in digits)
            {
                stack.Push(item);
            }

            Console.WriteLine("Stack BEFORE reversal :");
            foreach (var item in stack)
            {
                Console.Write(item);
            }

            Console.WriteLine();

            ReverseStackRecursive(stack);

            Console.WriteLine("Stack AFTER reversal :");
            while (stack.Count > 0)
            {
                Console.Write(stack.Pop());
            }

            Console.WriteLine();
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            SequenceParser.WarningMessage();

            var stack = new Stack <int>();

            for (int i = 0; i < 200; i++)
            {
                stack.Push(i);
            }

            Console.WriteLine(new string('=', 60));
            Console.WriteLine("PUSHING to stack");
            foreach (var st in stack)
            {
                Console.Write($"{st} ");
            }

            Console.WriteLine(new string('=', 60));
            Console.WriteLine("POPING from stack");
            for (var i = 0; i < 200; i++)
            {
                Console.Write($"{stack.Pop()} ");
            }
        }
コード例 #3
0
        public static void Main(string[] args)
        {
            SequenceParser.WarningMessage();
            Console.WriteLine("Task 1 : Enter a sequence of positive integer digits (like: '1 2 3' or '1,2,3') \nto get sum and average");

            List <int> list = SequenceParser.StringNumberSequenceToList(Console.ReadLine());

            Console.WriteLine($"Sum: {list.Sum()}");
            Console.WriteLine($"Average: {list.Average()}");
        }
コード例 #4
0
        public static void Main(string[] args)
        {
            SequenceParser.WarningMessage();

            Console.WriteLine("Task 9 : ENTER an integer to specify the starting point (example: 2)");
            Console.WriteLine(".. Using the Queue<T> class write a program to print its first 50 members for given N. ..");

            int inputNumber = int.Parse(Console.ReadLine());

            var queue = GeneratQueueeElements(inputNumber, 50);

            PrintQueueElemenets(queue);
        }
コード例 #5
0
        public static void Main(string[] args)
        {
            SequenceParser.WarningMessage();

            Console.WriteLine("Task 4 : Enter sequence of Interegers (like: '1 2 2 2 3' or '1, 2, 2, 2, 3')");
            Console.WriteLine("To find the longest subsequence of equal digits (like: 2 2 2)");

            var digits = SequenceParser.StringNumberSequenceToList(Console.ReadLine());

            var result = MaximalSubsequenceOfEquals(digits);

            result.ForEach(x => Console.Write(x + " "));
            Console.WriteLine();
        }
コード例 #6
0
        public static void Main(string[] args)
        {
            SequenceParser.WarningMessage();

            Console.WriteLine("Task 6 : Enter sequence of Interegers (like: ' 4, 2, 2, 5, 2, 3, 2, 3, 1, 5, 2 ')");
            Console.WriteLine("Program that removes from given sequence all numbers that occur odd number of times.");

            var digits = SequenceParser.StringNumberSequenceToList(Console.ReadLine());

            digits = RemoveAllOddTimesOccuranceElementsWithFind(digits);

            digits.ForEach(x => Console.Write(x + " "));
            Console.WriteLine();
        }
コード例 #7
0
        public static void Main(string[] args)
        {
            SequenceParser.WarningMessage();

            var qu = new Queue <int>();

            for (int i = 0; i < 50; i++)
            {
                qu.Enqueue(i);
            }

            for (int i = 0; i < 50; i++)
            {
                Console.Write($" {qu.Dequeue()} ");
            }
        }
コード例 #8
0
        public static void Main(string[] args)
        {
            SequenceParser.WarningMessage();

            Console.WriteLine("Task 10 : ENTER an integer to specify the START point (example: 5) \n and then ENTER ENDING POINT");
            Console.WriteLine(" .. N2 = N+1 ; N3 = N+2; N4 = N*2 .. Write a program that finds the shortest sequence of operations \nfrom the list above that starts from N and finishes in M.. ..");

            Console.WriteLine("Enter N :");
            var start = int.Parse(Console.ReadLine());

            Console.WriteLine("Enter M : ");
            var end = int.Parse(Console.ReadLine());

            var queue = GeneratQueueeElements(start, end);

            PrintQueueElemenets(queue);
        }
コード例 #9
0
        public static void Main(string[] args)
        {
            SequenceParser.WarningMessage();
            Console.WriteLine("Task 3 : Enter sequence of Interegers (like: '1 -2 3' or '1,-2,3') to sort in increasing order");

            var digits = SequenceParser.StringNumberSequenceToList(Console.ReadLine());

            //// digits.Sort();

            var instance = new SelectionSort();

            instance.Sort(digits);

            Console.WriteLine("Ordered : ");
            digits.ForEach(x => Console.Write(x + " "));
            Console.WriteLine("Done! ");
        }
コード例 #10
0
        public static void Main(string[] args)
        {
            SequenceParser.WarningMessage();

            LinkedList <int> sampleList = new LinkedList <int>();

            sampleList.Add(-33);
            sampleList.Add(2);
            sampleList.Add(100);
            sampleList.Add(4);

            foreach (var item in sampleList)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine(new string('=', 40));
            Console.WriteLine($"First element : {sampleList.FirstElement.Value}");
            Console.WriteLine($"Last element : {sampleList.LastElement.Value}");
            Console.WriteLine($"Count of all elements added : {sampleList.Count}");
            Console.WriteLine(new string('=', 40));

            var head = sampleList.GetFirstNode();

            Console.WriteLine(head.Value);
            Console.WriteLine(head.NextItem.Value);
            Console.WriteLine(head.NextItem.NextItem.Value);
            Console.WriteLine(head.NextItem.NextItem.NextItem.Value);
            Console.WriteLine(new string('=', 40));

            var head2 = head.GetNextNode();

            Console.WriteLine(head2.Value);

            Console.WriteLine(new string('=', 40));
            var containsCheckOne = sampleList.Contains(-33);
            var containsCheckTwo = sampleList.Contains(-3300);

            Console.WriteLine($"do sample list contains -33 : {containsCheckOne}");
            Console.WriteLine($"do sample list contains -3300 : {containsCheckTwo}");

            sampleList.Remove(-33);
            Console.WriteLine(sampleList.GetFirst());
            Console.WriteLine(sampleList.LastElement.Value);
        }
コード例 #11
0
        public static void Main(string[] args)
        {
            SequenceParser.WarningMessage();

            Console.WriteLine("Task 5 : Enter sequence of Interegers (like: '1 2 -2 2 -3' or '1, 2, -2, 2, -3')");
            Console.WriteLine("To remove all negavtive occurances in the sequence");

            var digits = SequenceParser.StringNumberSequenceToList(Console.ReadLine());

            RemoveAllNegativeElements(digits);

            //// digits = RemoveAllNegativeWithFind(digits); // variant with linq FindAll()

            //// digits = RemoveAllNegativeWithWhere(digits); // variant with Linq Where() clause

            digits.ForEach(x => Console.Write(x + " "));
            Console.WriteLine();
        }
コード例 #12
0
        public static void Main(string[] args)
        {
            SequenceParser.WarningMessage();

            Console.WriteLine("Task 7 : Enter sequence of Interegers (example: ' 3, 4, 4, 2, 3, 3, 4, 3, 2 ')");
            Console.WriteLine(" Program that finds in given array of integers\n (all belonging to the range [0..1000]) how many times each of them occurs.");

            var digits = SequenceParser.StringNumberSequenceToArray(Console.ReadLine());

            var result = CountNumberOfOccuranceGroupBy(digits);

            //// var result = CountNumberOfOccuranceForeach(digits); // second "manual" variant

            foreach (var record in result)
            {
                Console.WriteLine($"{record.Key} is seen {record.Value} times");
            }
        }
コード例 #13
0
        public static void Main(string[] args)
        {
            SequenceParser.WarningMessage();

            Console.WriteLine("Task 8 : Enter sequence of Interegers (example: ' 2, 2, 3, 3, 2, 3, 4, 3, 3 ')");
            Console.WriteLine(" Write a program to find the majorant of given array (if exists).");

            var digits = SequenceParser.StringNumberSequenceToArray(Console.ReadLine());

            var result = _07.NumberOfOccuranceForEachElement.Startup.CountNumberOfOccuranceGroupBy(digits);

            result = result.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, x => x.Value);

            if (result.First().Value > result.Count / 2)
            {
                Console.WriteLine($"The majorant is the number : {result.First().Key}");
                Console.WriteLine($"NUmber of occurances : {result.First().Value}");
            }
            else
            {
                Console.WriteLine("No majorant element in this sequence");
            }
        }