54 lines
1.0 KiB
C#
54 lines
1.0 KiB
C#
|
namespace Codeforces
|
||
|
{
|
||
|
public class IOTester
|
||
|
{
|
||
|
private static readonly TextReader originalStdIn = Console.In;
|
||
|
private static StringReader? stdIn;
|
||
|
|
||
|
private static readonly TextWriter originalStdOut = Console.Out;
|
||
|
private static StringWriter? stdOut;
|
||
|
|
||
|
public static void Start()
|
||
|
{
|
||
|
stdOut = new StringWriter();
|
||
|
Console.SetOut(stdOut);
|
||
|
}
|
||
|
|
||
|
public static void End()
|
||
|
{
|
||
|
stdOut = null;
|
||
|
stdIn = null;
|
||
|
Console.SetOut(originalStdOut);
|
||
|
Console.SetIn(originalStdIn);
|
||
|
}
|
||
|
|
||
|
public static void SetInput(params string[] lines)
|
||
|
{
|
||
|
string input = string.Join(Environment.NewLine, lines);
|
||
|
stdIn = new StringReader(input);
|
||
|
Console.SetIn(stdIn);
|
||
|
}
|
||
|
|
||
|
public static string GetOutput()
|
||
|
{
|
||
|
if (stdOut == null)
|
||
|
{
|
||
|
return "";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return stdOut.ToString();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static string[] GetOutputLines()
|
||
|
{
|
||
|
return GetOutput().Split(Environment.NewLine);
|
||
|
}
|
||
|
|
||
|
public static IList<string> GetOutputLinesAsList()
|
||
|
{
|
||
|
return new List<string>(GetOutputLines());
|
||
|
}
|
||
|
}
|
||
|
}
|