using System;
using System.Collections.Generic;
internal class Program
{
static HashSet<string> FindAllPalindromes(string s)
{
HashSet<string> palindromes = new HashSet<string>();
for (int length = 1; length <= s.Length; length++)
{
for (int i = 0; i + length <= s.Length; i++)
{
if (IsPalindrome(s, i, i + length - 1))
palindromes.Add(s.Substring(i, length));
}
}
return palindromes;
}
static bool IsPalindrome(string s, int fromIndex, int toIndex)
{
while (fromIndex < toIndex)
{
if (s[fromIndex] != s[toIndex])
return false;
fromIndex++;
toIndex--;
}
return true;
}
static void Main(string[] args)
{
Console.Write("Input string: ");
string s = Console.ReadLine();
Console.WriteLine("\nList of all palindromes in the string:\n");
HashSet<string> palindromes = FindAllPalindromes(s);
foreach (string palindrome in palindromes)
Console.WriteLine(palindrome);
Console.ReadLine();
}
}