Exemplo n.º 1
0
        static void Main(string[] args)
        {
            AnagramsAndPalindromes ap = new AnagramsAndPalindromes();

            Console.Write("Enter a word:");
            string word1 = Console.ReadLine();

            // There will be duplicates if a letter appears twice in a string, therefore, use distinct.
            IEnumerable <string> anagrams = ap.GenerateAnagrams(string.Empty, word1).ToList().Distinct();

            //IEnumerable<string> anagrams = ap.GeneratePermutations(0, word1.Length-1, word1).ToList();

            foreach (var v in anagrams)
            {
                Console.WriteLine(v);
            }

            foreach (var v in anagrams)
            {
                if (ap.IsPalindrome(v))
                {
                    Console.WriteLine(v + " is also a palindrome");
                }
            }
            Console.ReadLine();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            AnagramsAndPalindromes ap = new AnagramsAndPalindromes();

            Console.Write("Enter first word:");
            string input1 = Console.ReadLine();

            Console.Write("Enter second word:");
            string input2 = Console.ReadLine();

            if (ap.IsAnagram(input1, input2))
            {
                Console.WriteLine(" \"{0}\" and \"{1}\" are Anagrams", input1, input2);
            }
            else
            {
                Console.WriteLine(" \"{0}\" and \"{1}\" are not Anagrams", input1, input2);
            }

            if (ap.IsPalindrome(input1))
            {
                Console.WriteLine(input1 + " is a Palindrome!");
            }
            else
            {
                Console.WriteLine(input1 + " is not a Palindrome!");
            }

            if (ap.IsPalindrome(input2))
            {
                Console.WriteLine(input2 + " is a Palindrome!");
            }
            else
            {
                Console.WriteLine(input2 + " is not a Palindrome!");
            }

            Console.ReadLine();
        }