Guide · C++ Programming Language
C++ Programming Language – Learning Guide
C++ builds on the C language: it adds classes, templates and a rich standard library (STL). It is the language most often used in informatics competitions, because it is fast and has ready-made data structures.
The lessons follow the order of learning: basics, loops, arrays and vectors, functions and strings, and then the STL.
- Primary and secondary school
- Competitions
- Examples in C++
vector, string and sort instead of hand-written arrays and sorting – the code is shorter and has fewer mistakes.
Some lessons linked below are available only in Serbian for now. They are marked (SR).
1 C++ basics
The first program, input and output (cin, cout), data types and operators.
Introduction to C++
The first program, cin and cout, differences from C.
Open lesson →Data in C++
Variables, data types and conversions.
Open lesson →Operators in C++
Arithmetic, relational and logical operators.
Open lesson →Branching in a program
The if, else if and switch statements in C++.
Open lesson →2 Loops
Repeating statements and processing a sequence of input data.
3 Arrays, matrices and vectors
Static arrays, matrices and the dynamic array vector.
Arrays in C++
Declaring, reading and processing an array.
Open lesson →Two-dimensional arrays (matrices)
Working with matrices in C++.
Open lesson →Dynamic matrices
Matrices whose size is given while the program runs.
Open lesson →Vector (dynamic array)
The vector class: push_back, size, going through the elements.
Open lesson →4 Functions, pointers and strings
Modular programming and working with text.
5 STL – the standard library
Ready-made data structures and algorithms that save time in competitions.
Data dictionary – maps
The map class: key–value, counting occurrences.
Open lesson →Data structures – learning map
Stack, queue, lists and DSU with examples in C++.
Open lesson →STL: pair, sort, set and priority_queue (SR)
Pairs, sorting with a comparator, binary search, sets and a priority queue.
Open lesson →Templates (SR)
Functions and classes that work with several types; your own stack.
Open lesson →6 Object-oriented programming in C++
Classes and objects, inheritance and polymorphism in C++. The same concepts in Java are in the Java lessons.
7 Solved tasks in C++
Solved tasks, mostly from competitions, with explanations and code.
Letter set – solution
Counting letters and the minimum of quotients.
Open lesson →Palindrome string – solution
Checking whether a text reads the same in both directions.
Open lesson →Number of bombs – solution
Going through a matrix and counting neighbours.
Open lesson →Removing elements from an array – solution
Deleting elements from an array without losing their order.
Open lesson →N queens – solution
Backtracking: placing queens on a chessboard.
Open lesson →All competition tasks
A guide to the tasks by competition level.
Open lesson →✎ A short example
Reading n numbers into a vector, sorting and printing them.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int n;
cin >> n;
// reading n numbers into a vector
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
// sorting in ascending order
sort(a.begin(), a.end());
for (int x : a) cout << x << " ";
cout << endl;
return 0;
}
