Vscode是常用的开发工具,代码插入能够把常见的代码嵌入智能提醒,减轻了很大的工作量,下面是我刷题的配置,直接复制黏贴到自己的cpp.json里就可以用了
左下角,打开设置,选择用户代码片段,选择自己的语言
{
// 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"
// }
"inc":{
"prefix": "inc",
"body":[
"#include <bits/stdc++.h>",
"",
"using namespace std;",
"",
"",
"",
"int main()",
"{",
"",
"",
" cout << a << endl;",
" return 0;",
"}",
],
"description": "头文件和主函数框架"
},
"输入长度为n的数组":{
"prefix": "nnum",
"body":[
"int n;",
"cin >> n;",
"vector<int> num;",
"for (int i = 0; i < n; ++i) {",
"int a;",
"cin >> a;",
"num.emplace_back(a);",
"}",
"Solution s;",
],
"description": "输入长度为n的数组"
},
"输入不定长数组":{
"prefix": "bnuminput",
"body":[
"vector<int> arr;",
"int n = 0;",
"while (cin >> n) {",
"arr.emplace_back(n);",
"if (cin.get() == '\n') break;// 遇到回车后停止输入",
"}",
"Solution s;",
],
"description": "输入不定长度的数组,回车停止输入"
},
"输入一行字符串":{
"prefix": "strinput",
"body":[
"string inputStr;",
"getline(cin, inputStr);",
"Solution s;",
],
"description": "输入一行字符串"
},
"for循环遍历":{
"prefix": "fori",
"body":[
"for (int i = 0; i < ${1:num.size()}; ++i) {",
" ",
"}",
],
"description": "for循环遍历"
},
"auto循环遍历":{
"prefix": "auto",
"body":[
"for (const auto& i : ) {",
" ",
"}",
],
"description": "auto循环遍历"
},
"自定义结构体Node":{
"prefix": "nodestruct",
"body":[
"typedef struct ${1:Node} {",
" ${2:int} ${3:a}; ",
" ${4:int} ${5:b};",
" $1() : $3(0), $5(0) {}",
" $1($2 $3, $4 $5) : $3($3), $5($5) {}",
"} $1;",
],
"description": "自定义结构体Node"
},
"自定义外部比较函数,sort要加()":{
"prefix": "cmp",
"body":[
"struct cmp {",
" bool operator()(const ${1:int}& a, const $1& b)",
" {",
" return",
" }",
"};",
],
"description": "自定义外部比较函数,sort要加()"
},
"leetcode核心代码模版":{
"prefix": "solu",
"body":[
"class Solution {",
" ${1:int} ${2:Func}(const int& a)",
" {",
" ",
" }",
"};",
],
"description": "leetcode核心代码模版"
}
}