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("2"); WillReturn.Add("oxxoxxo"); WillReturn.Add("ooooxxo"); } else if (InputPattern == "Input2") { WillReturn.Add("5"); WillReturn.Add("ooxxxxx"); WillReturn.Add("ooooooo"); } else if (InputPattern == "Input3") { WillReturn.Add("1"); WillReturn.Add("oxxxxxo"); WillReturn.Add("xoxxxxo"); } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List InputList = GetInputList(); int D = int.Parse(InputList[0]); string DayStr = InputList[1] + InputList[2]; //前後に有給休暇の数分の平日を付加 DayStr = new string('x', D) + DayStr + new string('x', D); int UB = DayStr.Length - 1; var AnswerKouhoList = new List(); for (int I = 0; I <= UB; I++) { //現在の添字から連続したD日分の平日があったら、解の候補 if (I + D - 1 > UB) break; string wkSubStr = DayStr.Substring(I, D); if (wkSubStr.Contains('o')) continue; var wkCharList = new List(); for (int J = 0; J <= UB; J++) { if (I <= J && J <= I + D - 1) wkCharList.Add('o'); else wkCharList.Add(DayStr[J]); } AnswerKouhoList.Add(new string(wkCharList.ToArray())); } //AnswerKouhoList.ForEach(X => Console.WriteLine(X)); Console.WriteLine(AnswerKouhoList.Max(X => DeriveMaxSeqCnt(X))); } //String型を引数として、最大のoの連続数を返す static int DeriveMaxSeqCnt(string pDayStr) { int MaxSeqCnt = 0; int CurrSeqCnt = 0; foreach (char EachChar in pDayStr) { if (EachChar == 'o') CurrSeqCnt++; //休日だった場合 else CurrSeqCnt = 0;//平日だった場合 if (MaxSeqCnt < CurrSeqCnt) MaxSeqCnt = CurrSeqCnt; } return MaxSeqCnt; } }