Lesson 1 of 50 beginner

What is Competitive Programming?

Discover the world's most exciting brain sport — where coding meets competition!

Open interactive version (quiz + challenge)

Real-world analogy

Competitive Programming is like a cooking competition. You are given ingredients (the input), you must follow the recipe rules (the problem statement), and you need to cook the perfect dish (the output) as fast as you can. The fastest chef with the tastiest dish wins!

What is it?

Competitive Programming (CP) is a mind sport where participants solve well-defined programming problems within a time limit. You read a problem, think of a solution, write code, and submit it to an automated judge that instantly tells you if you are right or wrong. It combines logical thinking, math, and coding into one thrilling activity.

Real-world relevance

CP skills are used everywhere in the real world. Search engines like Google use algorithms to find the best results in milliseconds. GPS apps use shortest-path algorithms (a classic CP topic) to find the fastest route to your destination. Video games use optimization to render millions of pixels smoothly. Even social media feeds use sorting and filtering — all things you learn in CP!

Key points

Code example

#include <bits/stdc++.h>  // Include all standard libraries at once
using namespace std;       // So we can write cout instead of std::cout

int main() {
    // Your very first CP-style program!
    // It reads a number and prints a greeting.

    int age;                // Create a box to hold a whole number
    cout << "How old are you? ";  // Print a question to the screen
    cin >> age;             // Read the user's answer into our box

    if (age < 13) {         // Check: is the number less than 13?
        cout << "Wow, a young CP champion in the making!" << endl;
    } else {                // Otherwise (13 or older)
        cout << "Welcome to Competitive Programming!" << endl;
    }

    cout << "Let the adventure begin!" << endl;  // One last message
    return 0;               // Tell the computer we are done
}

Line-by-line walkthrough

  1. 1. We start with #include — this is a magic line that gives us access to ALL the tools C++ has. Think of it as opening a giant toolbox.
  2. 2. using namespace std; — this lets us use shortcuts like cout and cin without writing std:: in front every time. It saves us typing!
  3. 3. int main() { — this is where every C++ program starts running. It is like the starting line of a race. The computer begins here.
  4. 4. int age; — we create a memory box called 'age' that can hold a whole number. Right now the box is empty.
  5. 5. cout << "How old are you? "; — cout (see-out) prints text to the screen. The << arrows point toward cout, meaning 'send this text to the screen.'
  6. 6. cin >> age; — cin (see-in) waits for you to type something. The >> arrows point toward age, meaning 'put what the user typed into the age box.'
  7. 7. if (age < 13) { ... } — this checks a condition. If the age is less than 13, it runs the code inside the curly braces. Otherwise it skips to the else part.
  8. 8. else { ... } — if the condition above was false (age is 13 or more), the computer runs this code instead.
  9. 9. cout << "Let the adventure begin!" << endl; — prints one more message. endl means 'go to a new line' (like pressing Enter).
  10. 10. return 0; — this tells the computer 'I am done, everything went well.' The 0 means 'no errors.' It is like saying 'The End' in a story.

Spot the bug

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

int main() {
    int score;
    cin >> score;
    if (score = 100) {
        cout << "Perfect score!" << endl;
    }
    return 0;
}
Need a hint?
Look very carefully at the if statement. In C++, there is a big difference between = and ==. One gives a value, the other checks a value.
Show answer
The bug is on the line 'if (score = 100)'. The single = is an assignment (it SETS score to 100), not a comparison. It should be 'if (score == 100)' with double equals, which CHECKS if score equals 100. This is one of the most common bugs in C++!

Explain like I'm 5

Imagine you and your friends play a game where someone asks a tricky question, and you all race to answer it first — but instead of shouting the answer, you have to tell a computer how to figure it out. The computer checks if you are right, and the fastest correct answer wins. That is Competitive Programming! It is like a fun puzzle race using computers.

Fun fact

The youngest gold medalist at the International Olympiad in Informatics (IOI) was just 14 years old! And the top-rated Codeforces user, tourist (Gennady Korotkevich), started competing at age 11. He has won practically every major CP competition in the world — multiple times. So no matter your age, you are never too young (or too old) to start!

Hands-on challenge

Go to codeforces.com and create a free account. Then visit the problemset page and just READ one easy problem (rated 800). Do not worry about solving it yet — just read it and try to understand what it is asking. Write down in your own words: what is the input? What is the output? That is your first step!

More resources

Open interactive version (quiz + challenge) ← Back to course: CP Zero to Hero