1
0
codeforces-template/Codeforces.Console/IOTester.cs

54 lines
1.0 KiB
C#
Raw Normal View History

2023-08-09 09:42:50 +03:00
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)
{
2023-08-09 15:10:40 +03:00
return string.Empty;
2023-08-09 09:42:50 +03:00
}
else
{
return stdOut.ToString();
}
}
public static string[] GetOutputLines()
{
2023-08-09 15:10:40 +03:00
return GetOutput().Split(Environment.NewLine).SkipLast(1).ToArray();
2023-08-09 09:42:50 +03:00
}
public static IList<string> GetOutputLinesAsList()
{
return new List<string>(GetOutputLines());
}
}
}