swathi sathya prakash
BAN USERusing System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace test
{
public class Program
{
static void Main(string[] args)
{
string s = "ABCBAHELLOHOWRACECARAREYOUIAMAIDOINGGOOD";
String str="";
char[] a = s.ToCharArray();
for (int j = 0; j < a.Length; j++)
{
String tempchar = a[j].ToString();
for (int temp = j+1; temp < a.Length; temp++)
{
tempchar = String.Concat(tempchar, a[temp]);
if (ispalindrome(tempchar))
{
if (tempchar.Length > str.Length)
{
str = tempchar;
}
}
}
}
Console.WriteLine(str);
Console.ReadLine();
}
public static bool ispalindrome(string s1)
{
char[] arr = s1.ToCharArray();
Array.Reverse(arr);
string s2 = new String(arr);
if (s1.Equals(s2) == true)
{
return true;
}
return false;
}
}
}
This was asked in Philips too ..
- swathi sathya prakash January 30, 2014