ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules

How to write C# solutions

Programs written in C# language are compiled on the server with .NET 8.0 (.NET SDK 8.0.100 x64, C# 12). The compiler is invoked with the following arguments:

dotnet.exe csc.dll -optimize+ -define:ONLINE_JUDGE %1

The default stack size is set to 1 MB.

Examples of solving problems

This is a sample solution for the A + B problem in the C# language:

var tokens = Console.ReadLine().Split();
var a = int.Parse(tokens[0]);
var b = int.Parse(tokens[1]);
Console.WriteLine(a + b);

Here is an example of a simple solution for the Reverse root problem in the C# language. It demonstrates some language features but it’s not the most efficient one. With character by character input you can get much less working time and memory usage.

System.Globalization.CultureInfo.DefaultThreadCurrentCulture =
   System.Globalization.CultureInfo.InvariantCulture;

var result = Console.In.ReadToEnd()
   .Split()
   .Where(s => s != "")
   .Select(double.Parse)
   .Reverse()
   .Select(Math.Sqrt);

foreach (var d in result)
   Console.WriteLine($"{d:0.####}");

Input/output

The standard input/output methods like Console.ReadLine, String.Split and Console.WriteLine are not always sufficient. In some problems it’s necessary to manually implement fast input reading or output formatting.

In some problems numbers are not necessarily separated with a single space. Instead of

Console.ReadLine().Split()

use this code

Console.ReadLine().Split().Where(s => s != "")

Do not forget that the program can have any default culture. This is important when you need to read or write floating-point numbers: decimal separator can be configured in the system equal to either “.” or “,”. Currently the separator is set to “.” on the server, but it may be changed in the future. In order not to face culture problems pass invariant culture to all parse/formatting operation or set default culture for whole program:

System.Globalization.CultureInfo.DefaultThreadCurrentCulture =
   System.Globalization.CultureInfo.InvariantCulture;

Version history

From To Name Language Runtime
December 31, 2006 February 8, 2009 Visual C# 2005 C# 2.0 .NET Framework 2.0
February 8, 2009 August 4, 2010 Visual C# 2008 C# 3.0 .NET Framework 3.5
August 4, 2010 September 1, 2017 Visual C# 2010 C# 4.0 .NET Framework 4.0
February 18, 2013 September 1, 2017 Visual Basic 2010 VB 10.0 .NET Framework 4.0
September 1, 2017 September 1, 2020 Visual C# 2017 C# 7.1 .NET Framework 4.7
September 1, 2020 January, 22 2024 C# .NET Core 3.1 C# 8.0 .NET Core 3.1.4
January, 22 2024 C# .NET 8 C# 12.0 .NET 8.0.0