Setting up a C++ Competitive Programming Environment

11 May, 2022
In this article, we will learn about how to setup all in one Competitive Programming Environment
It is always recommended to use a Linux based OS. It is so because not only you will learn some better know-hows of the system but also will be able to get some pre-installed coding tools.I would highly recommend a Linux system myself. For Starters Ubuntu is quite fine. Advance users may go with ArchLinux or Kali Linux. Even if you don’t want to change your OS, Please use latest versions of Windows (7 or later).
Download Ubuntu Desktop
There are quite a number of good text editors available in market these days like VS Code, Sublime text, Atom, Notepad++, etc.My personal favorite is Sublime Text 3 because of it being lightweight, minimally aesthetic, and high functionalities.
Download SublimeText 3
Now is the time to choose a language to use. Most of the people use C++ as their primary coding language. This is mainly because of its speed, clarity and widespread support. So you should use C++ if you’re new to coding, but if you don’t know C++ but some other language, try focusing on that language only. Most of the CP Online judges will do things like variable time limits and all for other languages. ie. if your language is 2x slower than C++ then you would get 2x time limit too as compared to a C++ program.
Now if you are using C++ as your primary coding language you have to install a gcc compiler (Linux users can skip this step as most of the Linux Distros come with a compiler :)), If you are unsure if you have a gcc compiler or not; open-shell(ie cmd) and execute following code. If you get a answer then you are ready to go. If not(ie system do not understand the command) you have to install a compiler first.
g++ –version
Download MinGW compiler
Now this is the most important step of the article...”the touchup”.
C++
#include<bits/stdc++.h>using namespace std;void solve();int main(){   ios_base::sync_with_stdio(false);cin.tie(NULL);      #ifndef ONLINE_JUDGE   freopen("input.txt", "r", stdin);   freopen("error.txt", "w", stderr);   freopen("output.txt", "w", stdout);   #endif      int t=1;   ${2:/*is Single Test case?*/}cin>>t;   while(t--)   {      solve();      cout<<"\n";   }      cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;   return 0;}void solve(){}
If you are using Sublime Text then follow these steps to get a templateopen sublime and go to tools>developer>new snippet and click on itreplace the existing code with the code written above and save it with some name.
If you are using some other text editor, here is the template you should use:
C++
#include <bits/stdc++.h>using namespace std;void solve();int main(){    ios_base::sync_with_stdio(false);    cin.tie(NULL);  #ifndef ONLINE_JUDGE    freopen("input.txt", "r", stdin);    freopen("error.txt", "w", stderr);    freopen("output.txt", "w", stdout);#endif      int t = 1;    /*is Single Test case?*/ cin >> t;    while (t--) {        solve();        cout << "\n";    }      cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;    return 0;}void solve(){}
All coding sites use a file comparison method to check answers. It means they store the output through your program in a text file and compare with the actual answer file.Therefore you should also do so. What you need to do is create a folder and inside it create 3 files input.txt, output.txt, and error.txt. You should also place your cpp code here. After that you should configure your editor to a layout shown in the figure:
For configuring Sublime Text layout as shown in the above image follow the below steps1. View -> Layout -> Columns: 4 ( This will split the window into 4 columns )2. View -> Groups -> Max Columns: 2 ( This will squeeze the last 3 columns for input.txt, output.txt and error.txt into a single column ) 
Pay attention to files that are open in the editor.
It is recommended to have the copy of all your codes with yourself. Therefore it is good to use a version control tool, like git.By the use of Git you can derive back any previous code you have ever written.I’ve scratched some code to automate the commit process(It requires SublimeText, Linux OS, and Git)Download GIT
PHP
{ "shell_cmd": "g++ \"${file}\" -o \"${file_path}\\\\${file_base_name}\"", "file_regex": "^(..[^:]):([0-9]+):?([0-9]+)?:? (.)$","shell_cmd": "g++ -O2 -std=c++11 \"${file}\" -o \"${file_path}\\\\${file_base_name}\" && \"${file_path}\\\\${file_base_name}\" < input.txt","working_dir": "${file_path}", "selector": "source.c, source.c++",   "variants": [ {   "name": "Run + Commit",  "shell_cmd": "g++ -O2 -std=c++11 \"${file}\" -o \"${file_path}\\\\${file_base_name}\" && \"${file_path}\\\\${file_base_name}\" < input.txt && git add \"${file}\" && git commit -m \"${file_base_name}\" " } ] }
To use the above code; Go to Sublime Text>Tools>Build System>New Built System and paste this code. Save the file with a name.and then again go to Tools>Build System and select the name that you have chosen for our new code.ALL Done... Now you can run your CPP code by using CTRL+SHIFT+B and choose from the 2 options.Notes:1. Make sure you execute: git init , in the folder before running CTRL+SHIFT+B for committing.2. The file’s commit message will be same as the fileName, so try to use a different cpp file if you need to track them separately. 
sooda367
thejesh venkata
CPP-Competitive-Programming
C++
C++ Programs
Competitive Programming
Git
Linux-Unix
Write From Home
CPP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Vector in C++ STL
Map in C++ Standard Template Library (STL)
Initialize a vector in C++ (7 different ways)
std::sort() in C++ STL
Bitwise Operators in C/C++
Header files in C/C++ and its uses
Sorting a Map by value in C++ STL
Program to print ASCII Value of a character
How to return multiple values from a function in C or C++?
Shallow Copy and Deep Copy in C++