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 s6kopapauni-bonn.
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:
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
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.
Follow these steps to redirect sample input to your script:
Run
and select Configuration per file
Execute in an external system terminal
Interact with the Python console after execution
ommand line options
and enter < path\to\sample
in the fieldKnown 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
Follow these steps to redirect sample input to your script:
Run
and select Edit Configuration…
Redirect input from
Follow these steps to redirect sample input to your programm:
Debug
select ProjectName Debug Properties
Configuration Properties
go to Debugging
< path\to\sample
in the Command Arguments
field, $(ProjectDir)
can be use to link to the projects directoryFollow these steps to redirect sample input to your programm:
Run
and select Edit Configuration…
Redirect input from