PrevNext

Running Code Locally

Authors: Benjamin Qi, Hankai Zhang, Anthony Wang, Nathan Wang, Nathan Chen, Owen Wang

Options for running your language of choice locally.

Which text editor or IDE should I use?

Depends on your personal preference. Try multiple and see which one you like best.

If you're just starting out, it's easier to begin by running code online and worry about running locally later. You can find more information about running code online here.

Using an IDE

Resources
IOIfor reference, software you can use at IOI

Please let us know if you have trouble with installation!

C++

Resources
GeanyLightweight, frequently used at IOI.
MicrosoftMore lightweight than Visual Studio Community, requires some configuration. See PAPS 2.1 and the docs for C++ setup instructions.
Code::BlocksWindows & Linux. Apparently was unstable at IOI.
AppleMac.
JetbrainsRequires a license, but free for students.

Java

It can be useful to use a Java IDE to take advantage of the powerful debugging features in Java.

Resources
JetBrainsfree
Eclipse Foundationfree
King's College Londonfree

Python

Python comes with a program, known as IDLE (Integrated Development and Learning Environment), that allows one to write and run Python code. It supports many features, such as syntax highlighting and automatic indentation, that one would normally expect from an IDE/text editor. However, feel free to use another editor or IDE if you want to.

Using Command Line

C++

You can run your C++ programs from the command line and use a text editor of your choice.

Text Editors

Resources
Fast, lightweight. Unlimited free evaluation period, though it will repeatedly ask you to purchase a license.
Classic text editor, usually preinstalled on Linux. Also see Neovim, MacVim
From the makers of Github.

Vim is probably the easiest way to print syntax-highlighted code on Mac, see the response to this post.

Sublime Text Notes (Ben)

  • I prefer the Mariana color scheme in place of the default.
    • open command palette (Cmd-Shift-P) -> change color scheme
  • subl symlink
    • Using /usr/local/bin/subl instead of ~/bin/subl worked for me on OS X Mojave.
  • Package - Sublime Linter (GCC)
    • highlights compilation errors and warnings from -Wall
    • can change compilation commands in linter.py
  • Package - Fast Olympic Coding (I don't use)
    • test manager can be useful
    • linting is covered by the above
    • stress testing is covered in Debugging
    • can't get debug to work

Further Instructions

See this module for information about installing, compiling, and running C++ from the command line.

Including <bits/stdc++.h>

You can use #include <bits/stdc++.h> in place of separately including libraries.

Usage

This is usable with GCC. However, Mac OS X uses Clang while Windows uses Microsoft Visual C++ (MVSC) by default. <bits/stdc++.h> is not a standard header file, so it will not work with the latter two. This is one of the reasons why you should not use <bits/stdc++.h> outside of competitive programming.

If you install GCC as described later in the module linked above, then you should be good to go.

OS-Specific Recommendations

This section is not complete.

Any help would be appreciated! Just submit a Pull Request on Github.

Linux

Windows

Geany or CodeBlocks?

Mac

XCode?

Using <bits/stdc++.h> Without Installing GCC

If you installed Clang on Mac, then you can download stdc++.h from here and move it into a folder named bits that is located in the same directory as where all other C++ header files are located. However, this is not recommended.

Resources
SOsolutions that may or may not work

Java

Installation

Linux

First, you can check if you have Java already installed by running java --version in the terminal. If it returns something like this:

openjdk 11.0.9.1 2020-11-04
OpenJDK Runtime Environment (build 11.0.9.1+1-Ubuntu-0ubuntu1.20.04)
OpenJDK 64-Bit Server VM (build 11.0.9.1+1-Ubuntu-0ubuntu1.20.04, mixed mode, sharing)

That means you have Java installed already. On the other hand, if you get something like this:

Command 'java' not found

You will have to download and install JDK. On most Linux distros, the JDK can be downloaded via the built in package manager.

Ubuntu/Debian

On Ubuntu, Debian, and other Ubuntu/Debian based distos, the JDK can be installed via apt. You can install the Java JDK from the default repositories by running: sudo apt install default-jdk.

After this finishes installing, if you run java --version again, you should get something like above.

Arch

On Arch and other Arch based distos (like Manjaro), the JDK can be installed via pacman. You can install the Java JDK from the default repositories by running: sudo pacman -S jdk-openjdk.

After this finishes installing, if you run java --version again, you should get something like above.

Fedora

On Fedora and other Red Hat based distos, the JDK can be installed via dnf. You can install the Java JDK from the default repositories by running: sudo dnf install java-openjdk-devel.x86_64.

After this finishes installing, if you run java --version again, you should get something like above.

Windows

First, can check if you already have Java installed by running java --version in cmd. If it returns something like this:

openjdk 11.0.9.1 2020-11-04
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.9.1+1)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.9.1+1, mixed mode)

That means that you have Java installed already. On the other hand, if you get something like this:

'java' is not recognized as an internal or external command,
operable program or batch file.

You will have to download and install JDK from here.

After it finishes installing, if you run java --version again, you should get something like above. Note: the installer should automatically add Java into the system PATH, but in the event that it doesn't, you can find more information on how to do that here.

macOS

First, can check if you already have Java installed by running java --version in the terminal. If it returns something like this:

openjdk 11.0.9.1 2020-11-04
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.9.1+1)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.9.1+1, mixed mode)

That means that you have Java installed already. On the other hand, if you get something like this:

-bash: java: command not found

You will have to download and install JDK from here.

After it finishes installing, if you run java --version again, you should get something like above.

Compiling and Running

Running a Java file off of the command-line is relatively simple after the JDK is downloaded.

Consider this code of Main.java and assume it is in a file on your computer:

public class Main {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}

Use the cd command on your console to get to the directory that contains Main.java. Then, run the following command to compile the code:

javac Main.java

If it runs successfully, a file called Main.class will show up in the same directory, which can be executed with the next command:

java Main

If everything goes accordingly, the console should output Hello World!.

If you do USACO-style file I/O, meaning that files are in the "local directory", then the files must be located in the same directory as the source code (if you use the above method). You can find a Java testing script for USACO here.

Python

Download Python through the official website. On Windows and Mac, you can download executable files directly; on Linux, you must either download the Python source code and compile from source, or obtain Python through your package manager.

Make sure that you are using the correct version of Python. Python 2 is quite different from Python 3 (but parts of the version number beyond 2. or 3. do not matter much). We generally recommend newcomers to use Python 3, but if you are used to programming in Python 2, that is OK too.

The Python version can matter when using the command line to run Python; sometimes, python3 must be used instead of python in order to run Python 3. Try both commands, and pay attention to the version that Python prints to determine if this is the case on your system. For example, running the following in Terminal on my computer produces:

python --version # prints Python 2.7.13
python3 --version # prints Python 3.8.1

Module Progress:

Join the USACO Forum!

Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!

Give Us Feedback on Running Code Locally!

Leave suggestions for us by making a post on the USACO Forum! Ex: Unclear sections, mislabeled problems, etc.

PrevNext