示例#1
0
        private static void TestStringManipulations()
        {
            // Permutations of a string
            Strings.StartStringPermutations("dysmoemgjiahna");     // 87,178,291,200 permutations !!! I/O will kill the processingz

            // Remove Adjacent Duplicate Chars in a string
            Console.WriteLine(MiscQuestions.RemoveAdjacentDuplicateChars("acxxxcyd"));
            Console.WriteLine(MiscQuestions.RemoveAdjacentDuplicateChars("aacxxxcyd"));
            Console.WriteLine(MiscQuestions.RemoveAdjacentDuplicateChars("acxxxcayd"));
            Console.WriteLine(MiscQuestions.RemoveAdjacentDuplicateChars("acxxxcaayd"));
        }
示例#2
0
        private static void TestIntToEngRomanConversion()
        {
            Console.WriteLine("4 = {0}", MiscQuestions.IntToWords(4));
            Console.WriteLine("39 = {0}", MiscQuestions.IntToWords(39));
            Console.WriteLine("40 = {0}", MiscQuestions.IntToWords(40));
            Console.WriteLine("41 = {0}", MiscQuestions.IntToWords(41));
            Console.WriteLine("49 = {0}", MiscQuestions.IntToWords(49));
            Console.WriteLine("50 = {0}", MiscQuestions.IntToWords(50));
            Console.WriteLine("52 = {0}", MiscQuestions.IntToWords(52));
            Console.WriteLine("99 = {0}", MiscQuestions.IntToWords(99));
            Console.WriteLine("100 = {0}", MiscQuestions.IntToWords(100));
            Console.WriteLine("101 = {0}", MiscQuestions.IntToWords(101));
            Console.WriteLine("275 = {0}", MiscQuestions.IntToWords(275));
            Console.WriteLine("499 = {0}", MiscQuestions.IntToWords(499));
            Console.WriteLine("500 = {0}", MiscQuestions.IntToWords(500));
            Console.WriteLine("501 = {0}", MiscQuestions.IntToWords(501));
            Console.WriteLine("999 = {0}", MiscQuestions.IntToWords(999));
            Console.WriteLine("1000 = {0}", MiscQuestions.IntToWords(1000));
            Console.WriteLine("1001 = {0}", MiscQuestions.IntToWords(1001));
            Console.WriteLine("2746 = {0}", MiscQuestions.IntToWords(2746));



            Console.WriteLine("4 = {0}", MiscQuestions.GetRomanNumber(4));
            Console.WriteLine("39 = {0}", MiscQuestions.GetRomanNumber(39));
            Console.WriteLine("40 = {0}", MiscQuestions.GetRomanNumber(40));
            Console.WriteLine("41 = {0}", MiscQuestions.GetRomanNumber(41));
            Console.WriteLine("49 = {0}", MiscQuestions.GetRomanNumber(49));
            Console.WriteLine("50 = {0}", MiscQuestions.GetRomanNumber(50));
            Console.WriteLine("52 = {0}", MiscQuestions.GetRomanNumber(52));
            Console.WriteLine("99 = {0}", MiscQuestions.GetRomanNumber(99));
            Console.WriteLine("100 = {0}", MiscQuestions.GetRomanNumber(100));
            Console.WriteLine("101 = {0}", MiscQuestions.GetRomanNumber(101));
            Console.WriteLine("275 = {0}", MiscQuestions.GetRomanNumber(275));
            Console.WriteLine("499 = {0}", MiscQuestions.GetRomanNumber(499));
            Console.WriteLine("500 = {0}", MiscQuestions.GetRomanNumber(500));
            Console.WriteLine("501 = {0}", MiscQuestions.GetRomanNumber(501));
            Console.WriteLine("999 = {0}", MiscQuestions.GetRomanNumber(999));
            Console.WriteLine("1000 = {0}", MiscQuestions.GetRomanNumber(1000));
            Console.WriteLine("1001 = {0}", MiscQuestions.GetRomanNumber(1001));
            Console.WriteLine("2746 = {0}", MiscQuestions.GetRomanNumber(2746));
        }
示例#3
0
        private static void Test_PrintSpiralMatrix()
        {
            int[,] mtrx = new int[5, 5] {
                { 2, -1, 2, -1, 4 }, { 2, 8, 2, -1, 4 }, { 2, -1, 2, -1, 4 }, { 2, -1, 2, -1, 4 }, { 2, -1, 2, -1, 4 }
            };
            Console.WriteLine(MiscQuestions.PrintMatrixInSpiralSequence(mtrx));

            mtrx = new int[6, 6] {
                { 2, -1, 2, -1, 4, -5 }, { 2, 8, 2, -1, 4, -5 }, { 2, -1, 2, -1, 4, -5 }, { 2, -1, 2, -1, 4, -5 }, { 2, -1, 2, -1, 4, -5 }, { -2, -1, -2, -1, 4, -5 }
            };
            Console.WriteLine(MiscQuestions.PrintMatrixInSpiralSequence(mtrx));

            mtrx = new int[2, 3] {
                { 1, 2, 3 }, { 4, 5, 6 }
            };
            Console.WriteLine(MiscQuestions.PrintMatrixInSpiralSequence(mtrx));

            mtrx = new int[2, 2] {
                { 1, 2 }, { 3, 4 }
            };
            Console.WriteLine(MiscQuestions.PrintMatrixInSpiralSequence(mtrx));

            mtrx = new int[1, 3] {
                { 6, 7, 8 }
            };
            Console.WriteLine(MiscQuestions.PrintMatrixInSpiralSequence(mtrx));

            mtrx = new int[3, 1] {
                { 6 }, { 7 }, { 8 }
            };
            Console.WriteLine(MiscQuestions.PrintMatrixInSpiralSequence(mtrx));

            mtrx = new int[1, 1] {
                { 6 }
            };
            Console.WriteLine(MiscQuestions.PrintMatrixInSpiralSequence(mtrx));
        }
示例#4
0
        static void Main(string[] args)
        {
            var x = Strings.StringToNumber("-123.45");

            x = Strings.StringToNumber("-123");
            x = Strings.StringToNumber("123");
            x = Strings.StringToNumber("123.45");

            Test_FindMAxSubmatrix();

            TestKadanesAlgo();

            //// Median Finding across two sorted arrays
            int[] M = new int[] { 0, 1, 8 };
            int[] N = new int[] { 2, 4, 9, 12 };

            MiscQuestions misc   = new MiscQuestions();
            int           median = misc.FindMedianOfTwoSortedArrays(M, N);

            M      = new int[] { 1, 2, 4, 8, 9, 10 };
            N      = new int[] { 3, 5, 6, 7 };
            median = misc.FindMedianOfTwoSortedArrays(M, N);

            /////BitTitan
            B.BitTitanQuestion q    = new B.BitTitanQuestion();
            B.Node             root = new B.Node('R');
            root.Children    = new B.Node[3];
            root.Children[0] = new B.Node('A');
            root.Children[1] = new B.Node('B');
            root.Children[2] = new B.Node('C');

            B.Node A = root.Children[0];
            A.Children    = new B.Node[2];
            A.Children[0] = new B.Node('D');
            A.Children[1] = new B.Node('E');

            B.Node BB = root.Children[1];
            BB.Children    = new B.Node[3];
            BB.Children[0] = new B.Node('F');
            BB.Children[1] = new B.Node('G');
            BB.Children[2] = new B.Node('H');

            B.Node C = root.Children[2];
            C.Children = new B.Node[] { new B.Node('I') };


            q.SetRightLink(root);


            //MyLinkedList l = new MyLinkedList(3);
            //l.InsertHead(4);
            //l.InsertAfter(5, 4);


            //bool has = l.HasDuplicate("abcgdjgA");
            //has = l.HasDuplicate("abcgdjA");
            //string str = l.RemoveDuplicate("abcgdjA");

            TestMyDictionary();

            // get nth unique char
            char c = Strings.NthUniqueChar("This is a string", 2);

            c = Strings.NthUniqueChar("This is a string", 5);
            c = Strings.NthUniqueChar("This is a string", 0);

            Minian[] m = new Minian[5] {
                new Minian {
                    Height = 70, Weight = 80
                },
                new Minian {
                    Height = 72, Weight = 70
                },
                new Minian {
                    Height = 79, Weight = 64
                },
                new Minian {
                    Height = 60, Weight = 64
                },
                new Minian {
                    Height = 70, Weight = 69
                }
            };

            LongestSubsequence ls = new LongestSubsequence();

            ls.FindLongestSubsequenceOfMinians(m);
        }