using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "Input5"; static List GetInputList() { var WillReturn = new List(); if (InputPattern == "Input1") { WillReturn.Add("2 1"); WillReturn.Add("1 2"); WillReturn.Add("2 3"); } else if (InputPattern == "Input2") { WillReturn.Add("2 0"); WillReturn.Add("0 3"); WillReturn.Add("2 1"); } else if (InputPattern == "Input3") { WillReturn.Add("3 0"); WillReturn.Add("2 3"); WillReturn.Add("0 5"); } else if (InputPattern == "Input4") { WillReturn.Add("43682 82641"); WillReturn.Add("54647 3647"); WillReturn.Add("92674 64591"); } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List InputList = GetInputList(); int[] wkArr = { }; Action SplitAct = (pIndY) => wkArr = InputList[pIndY].Split(' ').Select(X => int.Parse(X)).ToArray(); int ACntWhite, ACntBlack; int BCntWhite, BCntBlack; int TakeCntFromA, TakeCntFromB; SplitAct(0); ACntWhite = wkArr[0]; ACntBlack = wkArr[1]; SplitAct(1); BCntWhite = wkArr[0]; BCntBlack = wkArr[1]; SplitAct(2); TakeCntFromA = wkArr[0]; TakeCntFromB = wkArr[1]; Action DebugPrintAct = () => { //Console.WriteLine(new string('■', 20)); //Console.WriteLine("袋Aの白={0}、黒={1}。袋Bの白={2}、黒={3}", // ACntWhite, ACntBlack, BCntWhite, BCntBlack); }; DebugPrintAct(); //Aの袋からBの袋への移動 if (TakeCntFromA <= ACntBlack) { ACntBlack -= TakeCntFromA; BCntBlack += TakeCntFromA; } else { int FirstMoveCnt = ACntBlack; ACntBlack = 0; BCntBlack += FirstMoveCnt; int SecondMoveCnt = TakeCntFromA - FirstMoveCnt; ACntWhite -= SecondMoveCnt; BCntWhite += SecondMoveCnt; } DebugPrintAct(); //Bの袋からAの袋への移動 if (TakeCntFromB <= BCntWhite) { BCntWhite -= TakeCntFromB; ACntWhite += TakeCntFromB; } else { int FirstMoveCnt = BCntWhite; BCntWhite = 0; ACntWhite += FirstMoveCnt; int SecondMoveCnt = TakeCntFromB - FirstMoveCnt; BCntBlack -= SecondMoveCnt; ACntBlack += SecondMoveCnt; } DebugPrintAct(); Console.WriteLine(ACntWhite); } }