Skip to content

Instantly share code, notes, and snippets.

@saadmahboob
Forked from kodekracker/c++Template.cpp
Created March 29, 2017 21:33
Show Gist options
  • Select an option

  • Save saadmahboob/87eef3591878b95dcc456057020f85a9 to your computer and use it in GitHub Desktop.

Select an option

Save saadmahboob/87eef3591878b95dcc456057020f85a9 to your computer and use it in GitHub Desktop.

Revisions

  1. @kodekracker kodekracker revised this gist Oct 31, 2014. 1 changed file with 34 additions and 0 deletions.
    34 changes: 34 additions & 0 deletions c++Template.cpp
    Original file line number Diff line number Diff line change
    @@ -116,6 +116,40 @@ template <typename T> inline T readInt()
    /************************************/


    /******* Debugging Class Template *******/
    #define DEBUG

    #ifdef DEBUG

    #define debug(args...) (Debugger()) , args

    class Debugger
    {
    public:
    Debugger(const std::string& _separator = " - ") :
    first(true), separator(_separator){}

    template<typename ObjectType> Debugger& operator , (const ObjectType& v)
    {
    if(!first)
    std:cerr << separator;
    std::cerr << v;
    first = false;
    return *this;
    }
    ~Debugger() { std:cerr << endl;}

    private:
    bool first;
    std::string separator;
    };

    #else
    #define debug(args...) // Just strip off all debug tokens
    #endif

    /**************************************/

    /******** User-defined Function *******/


  2. @kodekracker kodekracker revised this gist Oct 12, 2014. 1 changed file with 18 additions and 19 deletions.
    37 changes: 18 additions & 19 deletions c++Template.cpp
    Original file line number Diff line number Diff line change
    @@ -31,9 +31,9 @@
    #include <string.h>
    #include <stdlib.h>
    #include <assert.h>

    using namespace std;

    /******* All Required define Pre-Processors and typedef Constants *******/
    #define SCD(t) scanf("%d",&t)
    #define SCLD(t) scanf("%ld",&t)
    @@ -49,7 +49,7 @@ using namespace std;
    #define RREP(i, j) RFOR(i, j, 0, 1)
    #define all(cont) cont.begin(), cont.end()
    #define rall(cont) cont.end(), cont.begin()
    #define FOREACH(it, l) for (typeof(l.begin()) it = l.begin(); it != l.end(); it++)
    #define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
    #define IN(A, B, C) assert( B <= A && A <= C)
    #define MP make_pair
    #define PB push_back
    @@ -71,20 +71,20 @@ typedef long int int32;
    typedef unsigned long int uint32;
    typedef long long int int64;
    typedef unsigned long long int uint64;

    /****** Template of some basic operations *****/
    template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
    template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
    /**********************************************/

    /****** Template of Fast I/O Methods *********/
    template <typename T> inline void write(T x)
    {
    int i = 20;
    char buf[21];
    // buf[10] = 0;
    buf[20] = '\n';

    do
    {
    buf[--i] = x % 10 + '0';
    @@ -95,7 +95,7 @@ template <typename T> inline void write(T x)
    putchar(buf[i]);
    } while (buf[i++] != '\n');
    }

    template <typename T> inline T readInt()
    {
    T n=0,s=1;
    @@ -110,31 +110,30 @@ template <typename T> inline T readInt()
    n = (n<< 3) + (n<< 1) + (p - '0');
    p=getchar();
    }

    return n*s;
    }
    /************************************/


    /******** User-defined Function *******/

    // write here global variables declaration and user-defined functions



    /**************************************/


    /********** Main() function **********/
    int main()
    {

    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    //freopen("output.txt","w",stdout);
    #endif

    int tc;
    tc = read(int);

    while(tc--){
    write(tc);
    }
  3. @kodekracker kodekracker revised this gist Oct 4, 2014. 1 changed file with 28 additions and 18 deletions.
    46 changes: 28 additions & 18 deletions c++Template.cpp
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,12 @@
    /*
    * Note: This template uses some c++11 functions , so you have to compile it with c++11 flag.
    * Example:- $ g++ -std=c++11 c++Template.cpp
    *
    * Author : Akshay Pratap Singh
    * Handle: code_crack_01
    *
    */

    /******** All Required Header Files ********/
    #include <iostream>
    #include <string>
    @@ -27,9 +31,9 @@
    #include <string.h>
    #include <stdlib.h>
    #include <assert.h>

    using namespace std;

    /******* All Required define Pre-Processors and typedef Constants *******/
    #define SCD(t) scanf("%d",&t)
    #define SCLD(t) scanf("%ld",&t)
    @@ -67,15 +71,20 @@ typedef long int int32;
    typedef unsigned long int uint32;
    typedef long long int int64;
    typedef unsigned long long int uint64;


    /****** Template of some basic operations *****/
    template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
    template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
    /**********************************************/

    /****** Template of Fast I/O Methods *********/
    template <typename T> inline void write(T x)
    {
    int i = 20;
    char buf[21];
    // buf[10] = 0;
    buf[20] = '\n';

    do
    {
    buf[--i] = x % 10 + '0';
    @@ -86,7 +95,7 @@ template <typename T> inline void write(T x)
    putchar(buf[i]);
    } while (buf[i++] != '\n');
    }

    template <typename T> inline T readInt()
    {
    T n=0,s=1;
    @@ -101,33 +110,34 @@ template <typename T> inline T readInt()
    n = (n<< 3) + (n<< 1) + (p - '0');
    p=getchar();
    }

    return n*s;
    }
    /************************************/


    /******** User-defined Function *******/



    // write here global variables declaration and user-defined functions

    /**************************************/


    /********** Main() function **********/
    int main()
    {

    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    freopen("output.txt","w",stdout);
    #endif

    int tc;
    tc = read(int);

    while(tc--){
    write(tc);
    }
    return 0;
    }
    /******** Main() Ends Here *************/
    /******** Main() Ends Here *************/
  4. @kodekracker kodekracker revised this gist Aug 27, 2014. 1 changed file with 49 additions and 44 deletions.
    93 changes: 49 additions & 44 deletions c++Template.cpp
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,7 @@
    /*
    * Author : Akshay Pratap Singh
    * Handle: code_crack_01
    */

    /******** All Required Header Files ********/
    #include <iostream>
    @@ -43,21 +47,22 @@ using namespace std;
    #define rall(cont) cont.end(), cont.begin()
    #define FOREACH(it, l) for (typeof(l.begin()) it = l.begin(); it != l.end(); it++)
    #define IN(A, B, C) assert( B <= A && A <= C)
    #define mp make_pair
    #define pb push_back
    #define MP make_pair
    #define PB push_back
    #define INF (int)1e9
    #define EPS 1e-9
    #define PI 3.1415926535897932384626433832795
    #define MOD 1000000007
    #define read(type) readInt<type>()
    const double pi=acos(-1.0);
    typedef pair<int, int> II;
    typedef pair<int, int> PII;
    typedef vector<int> VI;
    typedef vector<II> VII;
    typedef vector<string> VS;
    typedef vector<PII> VII;
    typedef vector<VI> VVI;
    typedef map<int,int> MPII;
    typedef set<int> SET;
    typedef multiset<int> MSET;
    typedef set<int> SETI;
    typedef multiset<int> MSETI;
    typedef long int int32;
    typedef unsigned long int uint32;
    typedef long long int int64;
    @@ -66,38 +71,38 @@ typedef unsigned long long int uint64;
    /****** Template of Fast I/O Methods *********/
    template <typename T> inline void write(T x)
    {
    int i = 20;
    char buf[21];
    // buf[10] = 0;
    buf[20] = '\n';

    do
    {
    buf[--i] = x % 10 + '0';
    x/= 10;
    }while(x);
    do
    {
    putchar(buf[i]);
    } while (buf[i++] != '\n');
    int i = 20;
    char buf[21];
    // buf[10] = 0;
    buf[20] = '\n';

    do
    {
    buf[--i] = x % 10 + '0';
    x/= 10;
    }while(x);
    do
    {
    putchar(buf[i]);
    } while (buf[i++] != '\n');
    }

    template <typename T> inline T readInt()
    {
    T n=0,s=1;
    char p=getchar();
    if(p=='-')
    s=-1;
    while((p<'0'||p>'9')&&p!=EOF&&p!='-')
    p=getchar();
    if(p=='-')
    s=-1,p=getchar();
    while(p>='0'&&p<='9') {
    n = (n<< 3) + (n<< 1) + (p - '0');
    p=getchar();
    }

    return n*s;
    T n=0,s=1;
    char p=getchar();
    if(p=='-')
    s=-1;
    while((p<'0'||p>'9')&&p!=EOF&&p!='-')
    p=getchar();
    if(p=='-')
    s=-1,p=getchar();
    while(p>='0'&&p<='9') {
    n = (n<< 3) + (n<< 1) + (p - '0');
    p=getchar();
    }

    return n*s;
    }
    /************************************/

    @@ -112,17 +117,17 @@ template <typename T> inline T readInt()
    int main()
    {

    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #endif
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #endif

    int tc;
    tc = read(int);
    int tc;
    tc = read(int);

    while(tc--){
    write(tc);
    }
    return 0;
    while(tc--){
    write(tc);
    }
    return 0;
    }
    /******** Main() Ends Here *************/
  5. @kodekracker kodekracker revised this gist Aug 17, 2014. 1 changed file with 39 additions and 40 deletions.
    79 changes: 39 additions & 40 deletions c++Template.cpp
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@

    /******** All Required Header Files ********/
    #include <iostream>
    #include <string>
    @@ -65,45 +66,44 @@ typedef unsigned long long int uint64;
    /****** Template of Fast I/O Methods *********/
    template <typename T> inline void write(T x)
    {
    int i = 20;
    char buf[21];
    // buf[10] = 0;
    buf[20] = '\n';

    do
    {
    buf[--i] = x % 10 + '0';
    x/= 10;
    }while(x);
    do
    {
    putchar(buf[i]);
    } while (buf[i++] != '\n');
    int i = 20;
    char buf[21];
    // buf[10] = 0;
    buf[20] = '\n';

    do
    {
    buf[--i] = x % 10 + '0';
    x/= 10;
    }while(x);
    do
    {
    putchar(buf[i]);
    } while (buf[i++] != '\n');
    }

    template <typename T> inline T readInt()
    {
    T n=0,s=1;
    char p=getchar();
    if(p=='-')
    s=-1;
    while((p<'0'||p>'9')&&p!=EOF&&p!='-')
    p=getchar();
    if(p=='-')
    s=-1,p=getchar();
    while(p>='0'&&p<='9') {
    n = (n<< 3) + (n<< 1) + (p - '0');
    p=getchar();
    }

    return n*s;
    T n=0,s=1;
    char p=getchar();
    if(p=='-')
    s=-1;
    while((p<'0'||p>'9')&&p!=EOF&&p!='-')
    p=getchar();
    if(p=='-')
    s=-1,p=getchar();
    while(p>='0'&&p<='9') {
    n = (n<< 3) + (n<< 1) + (p - '0');
    p=getchar();
    }

    return n*s;
    }
    /************************************/


    /******** User-defined Function *******/

    // write here your code

    /**************************************/

    @@ -112,18 +112,17 @@ template <typename T> inline T readInt()
    int main()
    {

    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #endif

    int tc;
    tc = read(int);
    int tc;
    tc = read(int);

    while(tc--){
    // write here your code
    write(tc);
    }
    return 0;
    while(tc--){
    write(tc);
    }
    return 0;
    }
    /******** Main() Ends Here *************/
  6. @kodekracker kodekracker revised this gist Jul 7, 2014. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion c++Template.cpp
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@

    /******** All Required Header Files ********/
    #include <iostream>
    #include <string>
    @@ -104,6 +103,7 @@ template <typename T> inline T readInt()

    /******** User-defined Function *******/

    // write here your code

    /**************************************/

    @@ -121,6 +121,7 @@ int main()
    tc = read(int);

    while(tc--){
    // write here your code
    write(tc);
    }
    return 0;
  7. @kodekracker kodekracker created this gist Jul 7, 2014.
    128 changes: 128 additions & 0 deletions c++Template.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,128 @@

    /******** All Required Header Files ********/
    #include <iostream>
    #include <string>
    #include <vector>
    #include <algorithm>
    #include <sstream>
    #include <queue>
    #include <deque>
    #include <bitset>
    #include <iterator>
    #include <list>
    #include <stack>
    #include <map>
    #include <set>
    #include <functional>
    #include <numeric>
    #include <utility>
    #include <limits>
    #include <time.h>
    #include <math.h>
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <assert.h>

    using namespace std;

    /******* All Required define Pre-Processors and typedef Constants *******/
    #define SCD(t) scanf("%d",&t)
    #define SCLD(t) scanf("%ld",&t)
    #define SCLLD(t) scanf("%lld",&t)
    #define SCC(t) scanf("%c",&t)
    #define SCS(t) scanf("%s",t)
    #define SCF(t) scanf("%f",&t)
    #define SCLF(t) scanf("%lf",&t)
    #define MEM(a, b) memset(a, (b), sizeof(a))
    #define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
    #define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
    #define REP(i, j) FOR(i, 0, j, 1)
    #define RREP(i, j) RFOR(i, j, 0, 1)
    #define all(cont) cont.begin(), cont.end()
    #define rall(cont) cont.end(), cont.begin()
    #define FOREACH(it, l) for (typeof(l.begin()) it = l.begin(); it != l.end(); it++)
    #define IN(A, B, C) assert( B <= A && A <= C)
    #define mp make_pair
    #define pb push_back
    #define INF (int)1e9
    #define EPS 1e-9
    #define PI 3.1415926535897932384626433832795
    #define MOD 1000000007
    #define read(type) readInt<type>()
    const double pi=acos(-1.0);
    typedef pair<int, int> II;
    typedef vector<int> VI;
    typedef vector<II> VII;
    typedef vector<VI> VVI;
    typedef map<int,int> MPII;
    typedef set<int> SET;
    typedef multiset<int> MSET;
    typedef long int int32;
    typedef unsigned long int uint32;
    typedef long long int int64;
    typedef unsigned long long int uint64;

    /****** Template of Fast I/O Methods *********/
    template <typename T> inline void write(T x)
    {
    int i = 20;
    char buf[21];
    // buf[10] = 0;
    buf[20] = '\n';

    do
    {
    buf[--i] = x % 10 + '0';
    x/= 10;
    }while(x);
    do
    {
    putchar(buf[i]);
    } while (buf[i++] != '\n');
    }

    template <typename T> inline T readInt()
    {
    T n=0,s=1;
    char p=getchar();
    if(p=='-')
    s=-1;
    while((p<'0'||p>'9')&&p!=EOF&&p!='-')
    p=getchar();
    if(p=='-')
    s=-1,p=getchar();
    while(p>='0'&&p<='9') {
    n = (n<< 3) + (n<< 1) + (p - '0');
    p=getchar();
    }

    return n*s;
    }
    /************************************/


    /******** User-defined Function *******/


    /**************************************/


    /********** Main() function **********/
    int main()
    {

    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif

    int tc;
    tc = read(int);

    while(tc--){
    write(tc);
    }
    return 0;
    }
    /******** Main() Ends Here *************/