Suresh Meenakshisundaram
BAN USERHere is the answer
public void Run()
{
ArrayList result = this.FindBiggestPalindrome("abcracecarabamalayalamabcdefghgfedcba12351");
result = this.FindBiggestPalindrome("ABCBAHELLOHOWRACECARAREYOUIAMAIDOINGGOOD");
}
public ArrayList FindBiggestPalindrome(string input)
{
ArrayList stringlist = new ArrayList();
int inputfirstindex = 0;
int inputlastindex = input.Length - 1;
int counter = 0;
while (inputfirstindex < inputlastindex)
{
for (int count = inputfirstindex; count <= inputlastindex - inputfirstindex; count++)
{
if (this.IsPalindrome(input.Substring(inputfirstindex, input.Length - count - inputfirstindex)) && input.Substring(inputfirstindex, input.Length - count - inputfirstindex).Length > 1)
{
stringlist.Add(input.Substring(inputfirstindex, input.Length - count - inputfirstindex));
}
counter++;
}
inputfirstindex++;
}
Console.WriteLine("Counter = " + counter);
return stringlist; ;
}
public bool IsPalindrome(string input)
{
Console.WriteLine(input);
bool result = true;
int min = 0;
int max = input.Length - 1;
while (min < max)
{
//Console.WriteLine(input[min].ToString().ToLowerInvariant() + "==" + input[max].ToString().ToLowerInvariant());
if (input[min].ToString().ToLowerInvariant() != input[max].ToString().ToLowerInvariant())
{
result = false;
break;
}
min++; max--;
}
return result;
}
This will work till 9999
/// <summary>
/// sureshsundar21@live.com
/// </summary>
public class NumberToString
{
Dictionary<int, string> dict = null;
public NumberToString()
{
dict = new Dictionary<int, string>();
dict.Add(1, "One"); dict.Add(2, "Two"); dict.Add(3, "Three"); dict.Add(4, "Four"); dict.Add(5, "Five");
dict.Add(6, "Six"); dict.Add(7, "Seven"); dict.Add(8, "Eight"); dict.Add(9, "Nine"); dict.Add(10, "Ten");
dict.Add(11, "Eleven"); dict.Add(12, "Twelve"); dict.Add(13, "Thirteen"); dict.Add(14, "Fourteen"); dict.Add(15, "Fifteen");
dict.Add(16, "Sixteen"); dict.Add(17, "Seventeen"); dict.Add(18, "Eighteen"); dict.Add(19, "Nighteen");
dict.Add(20, "Twenty"); dict.Add(30, "Thirty"); dict.Add(40, "Fourty"); dict.Add(50, "Fifty"); dict.Add(60, "Sixty");
dict.Add(70, "Seventy"); dict.Add(80, "Eighty"); dict.Add(90, "Nighty"); dict.Add(100, "hundread"); dict.Add(1000, "thousand");
}
public string ConvertToString(int input)
{
if (input < 10)
{
return (dict[input]);
}
else if (input > 9 && input < 20)
{
return (dict[input]);
}
else if (input > 20)
{
StringBuilder str = new StringBuilder();
List<KeyValuePair<int, int>> list = SplitNumber(input);
foreach (var entry in list)
{
if (entry.Value > 10 && entry.Key > 0)
{
str.Append(dict[Convert.ToInt32(entry.Key)]).Append(" ").Append(dict[Convert.ToInt32(entry.Value)]).Append(" ");
}
else if (entry.Value == 10 && entry.Key > 0)
{
str.Append(dict[(entry.Key * entry.Value)]).Append(" ");
}
else if (entry.Value == 1 && entry.Key > 0)
{
if (list.Count > 2)
str.Append(" and ");
str.Append(dict[entry.Key]);
}
}
return str.ToString();
}
return string.Empty;
}
public List<KeyValuePair<int, int>> SplitNumber(int input)
{
List<KeyValuePair<int, int>> list = new List<KeyValuePair<int, int>>();
int lenindex = 0;
string inputstr = Convert.ToString(input);
int len = inputstr.Length;
lenindex = len - 1;
int digit = 0;
while (lenindex > 0)
{
string divider = string.Empty;
//char =
for (int count = 0; count < lenindex; count++)
{
divider = divider + "0";
}
divider = "1" + divider;
digit = input / Convert.ToInt32(divider);
list.Add(new KeyValuePair<int, int>(digit, Convert.ToInt32(divider)));
input = input - (digit * Convert.ToInt32(divider));
lenindex--;
}
list.Add(new KeyValuePair<int, int>(input, 1));
return list;
}
}
It is 11.
- Suresh Meenakshisundaram April 30, 2013
This will work
- Suresh Meenakshisundaram February 19, 2014