IEnumerable <ProblemData> ReadData() { using (var stream = File.OpenText(DataFileName + ".in")) { var linenum = int.Parse(stream.ReadLine()); for (int index = 0; index < linenum; index++) { yield return(ProblemData.Parse(stream)); } } }
public void SolveAndWrite() { var dataList = ReadData(); ProblemData.InitData(); var resultList = dataList.AsParallel().AsOrdered() .WithDegreeOfParallelism(DegreeOfParallelism) .Select(d => d.Calc()) .Select((re, index) => string.Format("Case #{0}: {1}", index + 1, re)); using (var stream = File.CreateText(DataFileName + ".out.txt")) { foreach (var result in resultList) { stream.WriteLine(result); } } }