結果
問題 |
No.273 回文分解
|
ユーザー |
![]() |
提出日時 | 2015-09-05 07:18:41 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 28 ms / 2,000 ms |
コード長 | 1,577 bytes |
コンパイル時間 | 1,032 ms |
コンパイル使用メモリ | 115,784 KB |
実行使用メモリ | 19,584 KB |
最終ジャッジ日時 | 2024-06-25 13:28:43 |
合計ジャッジ時間 | 2,795 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "Input4"; static List<string> GetInputList() { var WillReturn = new List<string>(); 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<string> InputList = GetInputList(); string S = InputList[0]; //回文判定 Predicate<string> IsKaibun = (pStr) => pStr.SequenceEqual(pStr.Reverse()); //最長の回文以外は、1文字の回文とみなして //ナイーブに最長の回文を探す var KaibunList = new List<string>(); 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)); } }