Table of Contents
Competitive Programming - How to use samples for local testing
While doing the exercises on our competitive programming platform you may want to test your programs locally, before uploading them to the website. To do this you are provided with sample text files containing the input for your program. Smaller examples might be entered by hand using the terminal as stdin, but the more complex ones require a better solution.
This tutorial will shortly introduce different ways on how to direct the sample file's contents to your program as stdin input.
For feedback on or suggestions for this guide feel free to write an e-mail to s6kopapa
uni-bonn.
Redirecting on posix complient operating systems (Linux, macOS, ...)
To input the sample files while working on posix complient operating systems (Linux, macOS, …) or while using a terminal like cygwin on a Windows OS you can use this command to redirect the input. path/to/sample in these examples refers to wherever you saved the input files. myprogram is the name of the program you want to test.
For compiled languages (like c, rust), once you compiled the program, you can use the pipe operator to redirect the file's content:
./myprogram < path/to/sample
Under Windows ./myprogram is ./myprogram.exe.
For interpreted languages like Python (or Julia) you have to call the interpreter instead:
python myprogram.py < path/to/sample
For java programs you also have to call the java after compiling with javac:
java myprogram < path/to/sample
For more information:
Redirection while using Windows
To redirect your program's input while on a Windows OS you will need to use the Windows CMD. The command reamins almost the same:
myprogramm.exe < path\to\sample
Redirecting while using IDEs
On most IDEs you will be able to pass command line arguments to run your program with. Use the same commands as above, without the myprogram part as an argument in your IDE. The path to the test file has to be relative to the project directory or an absolute path.
Below you will find exampls for some IDE's.
Spyder for Python - Version 5.0.0 and above
Follow these steps to redirect sample input to your script:
- Go to
Runand selectConfiguration per file - in the dialog select
Execute in an external system terminal - tick
Interact with the Python console after execution - tick C
ommand line optionsand enter< path\to\samplein the field
Known issue: the console might instantly close after completion, to verify your results you can add an infinite loop at the end of your script, which will keep the terminal open. Do not forget to remove that hodling loop before uploading your solution.
while True:
hold = 1
PyCharm for Python - Community Version 2021.1.1
Follow these steps to redirect sample input to your script:
- Go to
Runand selectEdit Configuration… - in the dialog tick
Redirect input from - select the file in the input field
Visual Studio 2019 for c++
Follow these steps to redirect sample input to your programm:
- under
DebugselectProjectName Debug Properties - in the
Configuration Propertiesgo toDebugging - enter
< path\to\samplein theCommand Argumentsfield,$(ProjectDir)can be use to link to the projects directory
CLion for c and c++ - Version 2021.1.1
Follow these steps to redirect sample input to your programm:
- Go to
Runand selectEdit Configuration… - in the dialog tick
Redirect input from - select the file in the input field











