Skip to content

Instantly share code, notes, and snippets.

@jugshaurya
Last active September 4, 2021 20:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jugshaurya/f2603b2cf43404bac9b4eb0018f67513 to your computer and use it in GitHub Desktop.
Save jugshaurya/f2603b2cf43404bac9b4eb0018f67513 to your computer and use it in GitHub Desktop.
c++ template

Note

  • Go to File>Preferences>Snippets
  • or ctrl+Shift+p and enter snippets then create new global snppet file.
  • and use
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.

for loop

  "": {
    "prefix": "fora",
    "body": [
      "for (${1:size_t} ${2:i} = 0; ${2:i} < ${3:count}; ${2:i}++) {",
      "	$0 ",
      "}"
    ],
    "description": ""
  }
}

for loop 2d

  "": {
    "prefix": "forb",
    "body": [
      "for (${1:size_t} ${2:i} = 0; ${2:i} < ${3:count}; ${2:i}++) {",
			"	for (${4:size_t} ${5:i} = 0; ${5:i} < ${6:count}; ${5:i}++) {",
      "		$0 ",
      "	}"
      "}"
    ],
    "description": ""
  }
}

printVec

  "": {
    "prefix": "printVec",
    "body": [
      "cout << endl << \"==========\" << endl;",
      "for (auto &${1:var}: ${2:vec}) {",
      "	cout << ${1:arr} << \" \";",
      "}",
      "cout << endl << \"==========\" << endl;"
    ],
    "description": ""
  }
}

printVec 2d

  "": {
    "prefix": "printVec2",
    "body": [
      "cout << endl << \"==========\" << endl;",
      "for (auto &${1:var1}: ${2:vec}) {",
      "	for (auto &${3:var2}: ${1:var1}) {",
      "		cout << ${3:var2} << \" \";",
      "	}",
      "	cout << endl;",
      "}",
      "cout << \"==========\" << endl;"
    ],
    "description": ""
  }
}

printContainer

  "": {
    "prefix": "printCon",
    "body": [
      "cout << endl << \"==========\" << endl;",
      "for (auto it = ${1:container}.begin(); it != ${1:container}.end(); ++it) {",
      "	cout << *it << \" \";",
      "}",
      "cout << endl << \"==========\" << endl;"
    ],
    "description": ""
  }
}

print Arr

  "": {
    "prefix": "printArr",
    "body": [
      "cout << endl << \"==========\" << endl;",
      "for (${1:size_t} ${2:i} = 0; ${2:i} < ${3:count}; ++${2:i}) {",
      "	$0",
      "}",
      "cout << endl << \"==========\" << endl;"
    ],
    "description": ""
  }
}

print Arr 2d

  "": {
    "prefix": "printArr2",
    "body": [
      "cout << endl << \"==========\" << endl;",
      "for (${1:size_t} ${2:i} = 0; ${2:i} < ${3:count}; ++${2:i}) {",
      " for (${1:size_t} ${4:i} = 0; ${4:i} < ${5:count}; ++${4:i}) {",
      "		$0",
      "	}",
      "}",
      "cout << endl << \"==========\" << endl;"
    ],
    "description": ""
  }
}

Cpp

	"": {
		"prefix": "code",
		"body": [
			"// clang-format off",
			"#include<bits/stdc++.h>",
			"#include <ext/pb_ds/assoc_container.hpp>",
			"using namespace __gnu_pbds;",
			"using namespace std;",
			"",
			"#define int 						long long",
			"#define vi              vector<int>",
			"#define pii             pair<int,int>",
			"#define mii             map<int,int>",
			"#define pqmax           priority_queue<int>",
			"#define pqmin           priority_queue<int,vi,greater<int> >",
			"#define setbits(x)      __builtin_popcountll(x)",
			"#define zrobits(x)      __builtin_ctzll(x)",
			"#define mod             1000000007 // 1e9+7",
			"#define inf             1e18",
			"#define ps(x,y)         fixed<<setprecision(y)<<x",
			"#define mk(arr,n,type)	type *arr=new type[n];",
			"#define w(t)            int t; cin>>t; while(t--)",
			"#define pw(b,p)         pow(b,p) + 0.1",
			"#define endl						\"\\n\"",
			"mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());",
			"",
			"typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;",
			"",
			"void fastIO(){",
			"	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);",
			"}",
			"void IO (){",
			"	#ifndef ONLINE_JUDGE	",
			"	freopen(\"input.txt\", \"r\", stdin);",
			"	freopen(\"output.txt\", \"w\", stdout);",
			"	#endif",
			"}",
			"",
			"// clang-format on",
			"int32_t main(){",
			"	fastIO();",
			"	// for Google kickstart comment next to next line",
			"	// for running on command line comment next line and do ./filename < input.txt",
			"	IO();",
			"	/* Code goes here */",
			"	$1",
			"	return 0;",
			"}",
],
		"description": ""
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment