How Online Judge works ?

This article is written to explain the working of an Online Judge exclusively for the members of CodeChef GTBIT Club (under Technical Society of GTBIT).

Many of you would be new to competitive programming. The first thing which comes to our mind after submitting our first few programs is like,

“there is some problem with the online compiler”


“why is it showing such errors ?”

The reason behind this is that we actually do not know how this compiler is working at backend, or how exactly our code is being checked. So lets get started with the real thing.

An Online Judge is a software environment which judges your code on a website like Codechef, SPOJ, HackerEarth etc. Here we have a set of inputs stored in a file (say input.txt), which are fed to the program’s standard input stream. The output of program is collected in another file (output.txt). After that the output.txt file is compared with a file which contains the expected output. The result is returned accordingly (correct / incorrect).

There are redirection operators ( > and <) supported by shell of an operating system. (Eg. DOS, Bash etc). For those who don’t know about shell, it is just the command prompt of operating system. We write the following line on the DOS shell to test our code.

nameOfFile.exe < input.txt > output.txt


The above means “Feed the input to file ‘2.Number_Tower.exe’ from file ‘input.txt’ and save the output of program to ‘output.txt’. For a Java program , we can write this :

java NameOfMyProgram < input.txt > output.txt

The ‘<‘ operator means to read the input from specified file and ‘>’ operator means to redirect the output to the specified file. In this program, we had to just read no.s and print same to the console (which are now written to the file).

The content of input.txt file are :  (no.s on the left side in RED specify line no.s)1


After executing, the content of output.txt file are :  (no.s on the left side in RED specify line no.s)



While submitting your program to an online judge, please keep this in mind that it is the program and not the person who is judging your program.So don’t write like this

“Please enter a no.”

Just write the program as specified on the website in Input-Output Section. For eg.


So this was a simple article explaining how an online judge works. I will not share the program, otherwise your people won’t practice :p .


  1. using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace printNo
    class Program
    static void Main(string[] args)
    string lines = null;
    while (true)
    string check = Console.ReadLine();

    if (check == “e” || check == “E”)
    int a = 0;
    if (int.TryParse(check, out a))
    lines += check+”\n” ;
    Console.WriteLine(“Input :”);
    Console.Out.NewLine = “\r\n\r\n”;
    // Output the lines using the new newline sequence.
    // Console.ReadLine();



Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

CommentLuv badge