C++
Input: Standard Input (stdin)
Output: Standard Output (stdout)
Memory limit: 100 megabytes
Time limit: 1.0 seconds
Output: Standard Output (stdout)
Memory limit: 100 megabytes
Time limit: 1.0 seconds
I/O and Documentation
- Use either
cin
orscanf()
to get input. - Use either
cout
orprintf()
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 theint
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:
- When compiling, it can be useful to enable all warnings with the
-Wall
flag. This might point out more subtle errors in your code. - 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
. - Enable Optimisation Level 2
-O2
. -
Link with the 'm' (math) library
-lm
. The math library provides the functions declared in the <cmath> header, such asfmax
.
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
- Go to the submit tab and upload the addition program above by copy-pasting and selecting C++ in the language dropdown.
- Understanding submission feedback.
Sample Explanation
3 + 4 = 7
-
Sample Input 1
3 4
Sample Output 1
7