Training Site
Sideways banner

C++

Input: Standard Input (stdin)
Output: Standard Output (stdout)
Memory limit: 100 megabytes
Time limit: 1.0 seconds

I/O and Documentation

  • Use either cin or scanf() to get input.
  • Use either cout or printf() to write output.
  • You are permitted to view cppreference.com during an NZIC contest. Although this website can be harder to read, it is often the most reliable and comprehensive source of information and it gets easier to understand the more you use it.

Program Structure

  • Make sure you have a main function with the int return type.
  • Make sure you never return any non-zero value in main, otherwise your program will fail with a Runtime Error.

Compiling

We recommend that you install and use GCC. Compile with these flags...

g++ -Wall -std=gnu++17 -O2 -o executablename.exe filename.cpp -lm


Compiler flags explanation:

  1. When compiling, it can be useful to enable all warnings with the -Wall flag. This might point out more subtle errors in your code.
  2. Set the C++ standard version with the -std flag. Otherwise, the compiler will default to an older version with less supported features. Set the C++ Language Version -std=gnu++17.
  3. Enable Optimisation Level 2 -O2.
  4. Link with the 'm' (math) library -lm. The math library provides the functions declared in the <cmath> header, such as fmax.

To run the executable, type its name. On Linux and macOS it must be prepended with ./ (for example ./executablename).

Example

Adding two numbers. Numbers will be space separated on a single line.

#include <bits/stdc++.h>
using namespace std;

int main () {
    int a, b;
    cin >> a >> b;
    cout << a + b << endl;
}


Submit

Sample Explanation

3 + 4 = 7

  • Sample Input 1

    3 4
    

    Sample Output 1

    7