Writing code faster in C++ STL
Last Updated :
20 Jul, 2017
You are wondering some time coder write his code in 2 min or less how? No kidding! Although this tip may not be very useful for competitions such as ICPC or IOI. But there are recent ICPCs ranks where rank i and rank i + 1 are just separated by few minutes. When you can solve the same number of problems as your competitor, it is now down to coding skill and … typing speed.
Try this typing test at typingtest.com and follow the instructions there on how to improve your typing skill.
Many of them uses typedefs, shortcuts, or macros that are commonly used by competitive programmers to speed up the coding time. In this short section, we list down several examples as below.
#include <bits/stdc++.h>
typedef long long ll;
typedef vector< int > vi;
typedef pair< int , int > ii;
typedef vector<ii> vii;
typedef set< int > si;
typedef map<string, int > msi;
#define REP(i, a, b) \
for ( int i = int (a); i <= int (b); i++)
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define INF 2000000000 // 2 billion
#define MEMSET_INF 127 // about 2B
#define MEMSET_HALF_INF 63 // about 1B
int main()
{
ios_base::sync_with_stdio( false );
cin.tie(NULL);
return 0;
}
|
Here, typedef and #define are used to short the code and you can use as per your need in main method ios_base::sync_with_stdio(false); and cin.tie(NULL); use for fast io which is reduce the time of running code.
Related Articles:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...