public static void Main(string[] args) { Encoding encoding = new UTF8Encoding(false); string inFilePath = "/gcj/2017/d/in.txt"; string outFilePath = "/gcj/2017/d/out.txt"; List <string> resultLines = new List <string>(); using (StreamReader inStream = new StreamReader(inFilePath, encoding)) { int casesCount = int.Parse(inStream.ReadLine()); for (int caseNumber = 1; caseNumber <= casesCount; caseNumber++) { CaseInfo c = CaseInfo.Parse(inStream); string solution = c.Solve(); Console.WriteLine("Case #" + caseNumber + ": " + solution); resultLines.Add("Case #" + caseNumber + ": " + solution); //break; } } File.WriteAllLines(outFilePath, resultLines, encoding); Console.ReadKey(); }
public static CaseInfo Parse(StreamReader inStream) { string line1 = inStream.ReadLine(); string[] line1Parts = line1.Split(); int stageSize = int.Parse(line1Parts[0]); int modelsCount = int.Parse(line1Parts[1]); List <Position> modelsX = new List <Position>(); List <Position> modelsP = new List <Position>(); for (int i = 0; i < modelsCount; i++) { string line = inStream.ReadLine(); string[] lineParts = line.Split(); string model = lineParts[0]; int row = int.Parse(lineParts[1]); int col = int.Parse(lineParts[2]); Position p = new Position() { Row = row, Col = col }; if (model == "x" || model == "o") { modelsX.Add(p); } if (model == "+" || model == "o") { modelsP.Add(p); } } CaseInfo result = new CaseInfo(); result.StageSize = stageSize; result.ModelsX = modelsX; result.ModelsP = modelsP; return(result); }