void run() { if (UseStandardIO) { _inputStream = Console.In; _outputStream = Console.Out; } else { _inputStream = File.OpenText(InputFile); _outputStream = File.CreateText(Path.Combine(new FileInfo(GetType().Assembly.Location).Directory.Parent.Parent.Parent.FullName, OutputFile)); } int testsCount = int.Parse(_inputStream.ReadLine()); C.Precalc(); var solvers = new C[testsCount]; for (int i = 0; i < testsCount; ++i) { solvers[i] = new C(); solvers[i].ReadData(); } int done = 0; if (UseMultiThreading) { solvers.AsParallel().WithDegreeOfParallelism(Math.Max(Environment.ProcessorCount, 2) - 1).ForAll( solver => { solver.Solve(); Console.Title = (++done).ToString() + " of " + testsCount; }); } else { for (int i = 0; i < testsCount; ++i) { solvers[i].Solve(); Console.Title = (++done).ToString() + " of " + testsCount; } } for (int i = 0; i < testsCount; ++i) { Out.Write(string.Format("Case #{0}: ", i + 1)); solvers[i].WriteAnswer(); } Out.Flush(); if (UseStandardIO) { Console.ReadLine(); } else { Out.Close(); } }
void run() { if (IsTestingRun) { _inputStream = File.OpenText("input.txt"); _outputStream = Console.Out; } else { _inputStream = File.OpenText(Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads"), InputFile)); _outputStream = File.CreateText(Path.Combine(new FileInfo(GetType().Assembly.Location).Directory.Parent.Parent.Parent.FullName, OutputFile)); } Presolve(); int testsCount = int.Parse(_inputStream.ReadLine()); var solvers = new Solution[testsCount]; for (int i = 0; i < testsCount; ++i) { solvers[i] = new Solution(); solvers[i].ReadData(); } int done = 0; if (UseMultiThreading) { solvers.AsParallel().WithDegreeOfParallelism(Math.Max(Environment.ProcessorCount, 2)).ForAll( solver => { solver.Solve(); Console.Title = (++done).ToString() + " of " + testsCount; }); } else { for (int i = 0; i < testsCount; ++i) { solvers[i].Solve(); Console.Title = (++done).ToString() + " of " + testsCount; } } for (int i = 0; i < testsCount; ++i) { Out.Write(string.Format("Case #{0}: ", i + 1)); solvers[i].WriteAnswer(); } Out.Flush(); Out.Close(); if (IsTestingRun) { Console.WriteLine("ALL DONE!"); Console.ReadLine(); } }
/// <summary> /// Closes the IO instance, stopping the ability to write and read. /// </summary> public void Close() { //Check if (!Open) { return; } //Close ms.Close(); Out.Close(); In.Close(); }
/// <summary> /// Closes the log /// </summary> /// <param name="suspend">supresses the 'Log closed message' (ready for a 'Resume()' to append more lines)</param> public static void Close(bool suspend) { if (suspend) { WriteLine("Log suspended"); } else { WriteLine("Log closed normally"); } Out.Flush(); Out.Close(); }
/// <summary> /// Closes the IO and any open streams. /// </summary> public virtual void Close() { if (Opened) { if (Stream != null) { Stream.Dispose(); } if (In != null) { In.Close(); } if (Out != null) { Out.Close(); } Opened = false; } }
public static void runnerMain() { if (stdIn) { In = new Reader(Console.OpenStandardInput()); } else { In = new Reader(INPUT_FILE_NAME); } if (stdOut) { Out = new StreamWriter(Console.OpenStandardOutput()); } else { Out = new StreamWriter(OUTPUT_FILE_NAME); } for (int i = 1; i <= NUM_OF_TEST_CASES; i++) { try { run(i); } catch (Exception e) { Out.WriteLine("Exception thrown on test case " + i); Out.WriteLine(e.StackTrace); Out.Flush(); if (crash) { throw new Exception(); } } if (flush) { Out.Flush(); } } In.Close(); Out.Close(); }
/// <summary> /// Close and release all resources used by this client. /// </summary> public void Dispose() { if (!Alive) { Out.Close(); In.Close(); return; } up.WaitOne(); In.Close(); Out.Close(); up.Dispose(); SignalHandler = new Dispatcher <Message>(); if (OnClose != null) { OnClose(); } }
/// <summary> /// 销毁游戏资源 /// </summary> public void Dispose() { if (!mDisposed) { mDisposed = true; if (null != In) { In.Close(); In = null; } if (null != Out) { Out.Close(); Out = null; } if (null != Buffer) { Buffer.Close(); Buffer.Dispose(); Buffer = null; } } }