Competitive Programming: How to Get Started With C++

In this post, I will give a step-by-step tutorial on how to get started with C++, which is one of many popular programming languages, for the purpose of competitive programming.

Step 1: IDE and Compiler

First of all, you need to have an IDE and a compiler. Personally, I use Dev-C++ since this IDE comes with compiler inside.

Download link: http://www.bloodshed.net/devcpp.html

Step 2: Basic Structure

You need to understand the basic structure of C++ programming. Basically, there are only three fundamental elements:

  1. Library (#include …)
  2. using namespace std;
  3. int main() {}

Tutorial

The library is essential since you can import some classes and functions inside. You can imagine them as “tools” that can help you in writing your code. For example, if you want to use trigonometric functions, you can put #include<math.h>.

Putting “using namespace std;” is actually not a must, but it is really recommended because it makes your task easier and it makes everything tidier. Since this tutorial is primarily dedicated for those who want to be competitive programmers, it is not necessary to understand this part. Hence, for the sake of simplicity, I will not go deeper on this.

So where can you put your code? Well, you can put it inside the brackets after int main(), as you can see in the above picture

Step 3: Choosing the right library

The list of libraries can be found here: http://www.cplusplus.com/reference/. However, note that for C++, you have to use the one in (). For example, instead of using <cstdio>, you should use <stdio.h>.

“But how am I supposed to memorize every library for competitions?” Fortunately, you don’t need to, actually.

Step 3.1 (Shortcut): Always put #include<bits/stdc++.h>

Yes, that header is sort of a magic trick. When you put that in your code, it includes all other libraries so that you do not need to type every single library that you need. That one magic word is there to do it for you!

 

Well, writing the code itself is, of course, a daunting task. Therefore, I will definitely make another tutorial for that 🙂

See you all on the next post!!!

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this:
search previous next tag category expand menu location phone mail time cart zoom edit close