Skip to content

Instantly share code, notes, and snippets.

@ahmadsb86
Created October 24, 2023 20:03
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 ahmadsb86/d3a492d0313d952279c5cc65f855a214 to your computer and use it in GitHub Desktop.
Save ahmadsb86/d3a492d0313d952279c5cc65f855a214 to your computer and use it in GitHub Desktop.
CPP Snippets
{
// Place your snippets for cpp here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
"Template for CP programs": {
"prefix": "cp",
"body": [
"#include <bits/stdc++.h> ",
"using namespace std;",
"void setIO(string name = \"\") { // name is nonempty for USACO file I/O",
" ios_base::sync_with_stdio(0);",
" cin.tie(0); // see Fast Input & Output",
" // alternatively, cin.tie(0)->sync_with_stdio(0);",
" if (!name.empty()) {",
" freopen((name + \".in\").c_str(), \"r\", stdin); // see Input & Output",
" freopen((name + \".out\").c_str(), \"w\", stdout);",
" }",
"}",
"",
"int main(){",
" setIO(\"${1:problem_statement}\");"
" ${0}",
"}"
],
"description": "Template for CP programs"
},
"Cint": {
"prefix": "cint",
"body": [
"int ${1:x}; cin >> ${1:x};"
],
"description": "Cint"
}
,
"Dcint": {
"prefix": "dcint",
"body": [
"int ${1:x}, ${2:y}; cin >> ${1:x} >> ${2:y};"
],
"description": "Dcint"
},
"Ctring": {
"prefix": "ctring",
"body": [
"string ${1:x}; cin >> ${1:x};"
],
"description": "Ctring"
},
"Cout an end line": {
"prefix": "el",
"body": [
"<< \"\\n\";"
],
"description": "Cout an end line"
},
"Cout with endline": {
"prefix": "lcout",
"body": [
"cout << ${1:\"Hello World\"} << \"\\n\";"
],
"description": "Cout with endline"
},
"Cout ": {
"prefix": "cout",
"body": [
"cout << ${1:\"Hello World\"};"
],
"description": "Cout "
},
"Log value of variable": {
"prefix": "log",
"body": [
"cout << \"${1:var}: \" << ${1:var} << \"\\n\";"
],
"description": "Log value of variable"
},
"Print values of vector": {
"prefix": "printvec",
"body": [
"for (auto e: ${1:vec})",
" cout << e << \" \";",
"cout << \"\\n\";"
],
"description": "Print values of vector"
},
"Loop values of vector": {
"prefix": "loopvec",
"body": [
"for (auto e: ${1:vec}){",
" ${0}",
"}"
],
"description": "Loop values of vector"
},
"For Loop": {
"prefix": "for",
"body": [
"for (int i = 0; i < ${1:n}; i++){",
" ${0}",
"}"
],
"description": "For Loop"
},
"For Loop with control": {
"prefix": "FOR",
"body": [
"for (int ${1:i} = ${2:0}; ${1:i} < ${3:n}; ${1:i}++){",
" ${0}",
"}"
],
"description": "For Loop with control"
},
"Vector<int>": {
"prefix": "vi",
"body": [
"vector<int> ${0}"
],
"description": "Vector<int>"
}
"Pair<int,int>": {
"prefix": "pii",
"body": [
"pair<int,int> ${0}"
],
"description": "Pair<int,int>"
},
"Custom sort": {
"prefix": "customSort",
"body": [
"sort(${1:arr}, ${2:arr + n}, [](${3:int} a, ${3:int} b) {${4:return a < b;}});"
],
"description": "Custom sort"
},
"Set IO": {
"prefix": "setio",
"body": [
"void setIO(string name = \"\") { // name is nonempty for USACO file I/O",
" ios_base::sync_with_stdio(0);",
" cin.tie(0); // see Fast Input & Output",
" // alternatively, cin.tie(0)->sync_with_stdio(0);",
" if (!name.empty()) {",
" freopen((name + \".in\").c_str(), \"r\", stdin); // see Input & Output",
" freopen((name + \".out\").c_str(), \"w\", stdout);",
" }",
"}"
],
"description": "Set IO"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment