using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "Input4"; static List GetInputList() { var WillReturn = new List(); if (InputPattern == "Input1") { WillReturn.Add("ABACDDCEFGFE"); //5 } else if (InputPattern == "Input2") { WillReturn.Add("ZZ"); //1 } else if (InputPattern == "Input3") { WillReturn.Add("AABAAABBABBABBBAAABAA"); //8 } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List InputList = GetInputList(); string S = InputList[0]; //回文判定 Predicate IsKaibun = (pStr) => pStr.SequenceEqual(pStr.Reverse()); //最長の回文以外は、1文字の回文とみなして //ナイーブに最長の回文を探す var KaibunList = new List(); for (int I = 0; I <= S.Length - 1; I++) { for (int J = S.Length - 1; I <= J; J--) { string wkStr = S.Substring(I, J - I + 1); if (IsKaibun(wkStr) == false) continue; KaibunList.Add(wkStr); break; } } //分解してない回文をRemove KaibunList.RemoveAll(X => X == S); Console.WriteLine(KaibunList.Max(X => X.Length)); } }