From Wikipedia (http://en.wikipedia.org/wiki/Anagram)
An anagram is a type of word play, the result of rearranging the letters of a word or phrase to produce a new word or phrase, using all the original letters exactly once.
Program to check if two strings are anagrams are not
using System;
namespace StringAnagrams
{
class Program
{
static void Main(string[] args)
{
try
{
Console.WriteLine("Please enter the first string.");
string sFirst = Console.ReadLine();
Console.WriteLine("Please enter the second string.");
string sSecond = Console.ReadLine();
if (sFirst.Length == sSecond.Length)
{
char[] cFirst = sFirst.ToLower().ToCharArray();
char[] cSecond = sSecond.ToLower().ToCharArray();
Array.Sort<char>(cFirst);
Array.Sort<char>(cSecond);
if ((new string(cFirst)).Equals((new string(cSecond))))
Console.WriteLine("Anagrams");
else
Console.WriteLine("Not Anagrams");
}
else
Console.WriteLine("Not Anagrams");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.Read();
}
}
}
An anagram is a type of word play, the result of rearranging the letters of a word or phrase to produce a new word or phrase, using all the original letters exactly once.
Program to check if two strings are anagrams are not
using System;
namespace StringAnagrams
{
class Program
{
static void Main(string[] args)
{
try
{
Console.WriteLine("Please enter the first string.");
string sFirst = Console.ReadLine();
Console.WriteLine("Please enter the second string.");
string sSecond = Console.ReadLine();
if (sFirst.Length == sSecond.Length)
{
char[] cFirst = sFirst.ToLower().ToCharArray();
char[] cSecond = sSecond.ToLower().ToCharArray();
Array.Sort<char>(cFirst);
Array.Sort<char>(cSecond);
if ((new string(cFirst)).Equals((new string(cSecond))))
Console.WriteLine("Anagrams");
else
Console.WriteLine("Not Anagrams");
}
else
Console.WriteLine("Not Anagrams");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.Read();
}
}
}
No comments:
Post a Comment