zoukankan      html  css  js  c++  java
  • vscode 自定义用户代码片段

    在 vs code 界面先输入

    Ctrl + Shift + P
    

    接着输入

    configure user snippets
    

    然后找到 c++ ,然后复制下面的代码,以后输入 prefix 里的东西再回车即可

    {
    	// 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"
    	// }
    	"DEBUG-DEFINE":{
    		"prefix": "debug-define",
    		"body": [
    			"#define DEBUG",
    			"#define d1(x) std::cout << #x " = " << (x) << std::endl",
    			"#define d2(x, y) std::cout << #x " = " << (x) << " ," #y " = " << (y) << std::endl",
    			"#define disp(arry, fr, to) \",
    			"    { \",
    			"        std::cout << #arry " : "; \",
    			"        for(int _i = fr; _i <= to; _i++) std::cout << arry[_i] << " "; \",
    			"        std::cout << std::endl; \",
    			"    }",
    			"$0"
    		],
    		"description": "debug-define"
    	},
    	"for":{
    		"prefix": "forint i",
    		"body": [
    			"for(int ${1:Temporary}=${2:0};$1<${3:n};++$1)$0"
    		]
    	},
    	"scanf1":{
    		"prefix": "s1anf",
    		"body": [
    			"scanf("%${1:d}",&${2:Variable})$0"
    		],
    		"description": "scanf1"
    	},
    	"scanf2":{
    		"prefix": "s2anf",
    		"body": [
    			"scanf("%${1:d} %${3:d}",&${2:Variable1},&${4:Variable2})$0"
    		],
    		"description": "scanf2"
    	},
    	"scanf3":{
    		"prefix": "s3anf",
    		"body": [
    			"scanf("%${1:d} %${3:d} %${5:d}",&${2:Variable1},&${4:Variable2},&${6:Variable3})$0"
    		],
    		"description": "scanf3"
    	},
    	"base": {
            "prefix": "base", 
            "body": [
                "#include <bits/stdc++.h>",
                "",
                "#define ed end()",
                "#define bg begin()",
                "#define mp make_pair",
                "#define pb push_back",
                "#define vv(T) v(v(T))",
                "#define v(T) vector<T>",
                "#define all(x) x.bg,x.ed",
                "#define newline puts("")",
                "#define si(x) ((int)x.size())",
                "#define rep(i,n) for(int i=1;i<=n;++i)",
                "#define rrep(i,n) for(int i=0;i<n;++i)",
                "#define srep(i,s,t) for(int i=s;i<=t;++i)",
                "#define drep(i,s,t) for(int i=t;i>=s;--i)",
                "",
                "using namespace std;",
                "typedef long long ll;",
                "typedef pair<int,int> pii;",
                "const int Maxn = 1e5+10;",
                "const int Inf = 0x7f7f7f7f;",
                "const ll Inf_ll = 1ll*Inf*Inf;",
                "const int Mod = 1e9+7;",
                "const double eps = 1e-7;",
                "",
                "int main(){",
                "    $0",
                "    return 0;",
                "}",
            ],
            "description": "basic components"
            
    	},
    	"fread": {
            "prefix": "readint",
            "body": [
                "inline int r(){",
                "    char c = getchar();int x = 0,fh = 0;",
                "    while(c < '0' || c > '9'){fh |= c == '-';c = getchar();}",
                "    while(c >= '0' && c <= '9'){x = (x << 1) + (x << 3) + (c ^ 48);c = getchar();}",
                "    return fh?-x:x;",
                "}"
            ],
            "description": "fast read"
        },
        "quick_pow":{
            "prefix": "qpow",
            "body": [
                "ll mypow(ll a,ll b){",
                "    ll inv = 1;",
                "    while( b ){",
                "        if( b&1 )  inv = inv*a%Mod;",
                "        a = a*a%Mod;",
                "        b >>= 1;",
                "    }",
                "    return inv;",
                "}"
            ]
        },
        "GCD":{
            "prefix": "GCD",
            "body": [
                "ll gcd(ll a,ll b){",
                "    return b == 0 ? a : gcd(b,a%b);",
                "}"
            ]
        },
        "Linear_sieve":{
            "prefix": "Linear_sieve",
            "body": [
                "int prim[Maxn],tol,mu[Maxn],phi[Maxn];",
                "bool vis[Maxn];",
                "void Get(int n){",
                "    mu[1] = phi[1] = 1;",
                "    for(int i=2;i<=n;i++)",
                "    {",
                "        if( !vis[i] )  prim[++tol] = i,mu[i] = -1,phi[i] = i-1;",
                "        for(int j=1;j<=tol&&i*prim[j]<=n;j++)",
                "        {",
                "            vis[i*prim[j]] = true;",
                "            if( i%prim[j] == 0 )",
                "            {",
                "                phi[i*prim[j]] = phi[i]*prim[j];",
                "                break;",
                "            }",
                "            mu[i*prim[j]] = -mu[i];",
                "            phi[i*prim[j]] = phi[i]*(prim[j]-1);",
                "        }",
                "    }",
                "}"
            ]
        },
        "TTT":{
            "prefix": "TTT",
            "body": [
                "int T;",
                "scanf("%d",&T);",
                "for(int _=1;_<=T;_++)",
                "{",
                "    $1",
                "}",
            ]
        },
        "FAC":{
            "prefix": "FAC",
            "body": [
                "ll inv[Maxn],fac[Maxn],finv[Maxn];",
                "void Init(int n){",
                "    inv[0] = inv[1] = fac[0] = finv[0] = 1;",
                "    for(int i=2;i<=n;i++)",
                "        inv[i] = 1ll*(Mod - Mod/i)*inv[Mod%i]%Mod;",
                "    for(int i=1;i<=n;i++)",
                "        fac[i] = fac[i-1]*i%Mod,",
                "        finv[i] = finv[i-1]*inv[i]%Mod;",
                "}"
            ]
        },
        "ST_def":{
            "prefix": "ST_def",
            "body":[
                "#define L t<<1",
                "#define R L|1",
                "#define l(a) ST[a].l",
                "#define r(a) ST[a].r",
                "#define s(a) ST[a].sum"   
            ]
        },
        "fout":{
            "prefix": "outint",
            "body": [
                "void print(int x){",
                "    if( x < 0 )  x = -x;",
                "    if( x >= 10 ) print(x/10);",
                "    putchar(x%10+'0');",
                "}"
            ]
        },
        "freopen":{
            "prefix": "readfile",
            "body":[
                "freopen("1.in","r",stdin);",
                "freopen("1.out","w",stdout);"
            ]
        }
    }
    
    
  • 相关阅读:
    java 多线程 继承Thread和实现Runnable的区别
    TCP和UDP的区别
    重载与覆盖(java)
    感悟
    ant design + react带有二级导航菜单自动生成
    自己搭建ant design框架
    ant design框架学习
    radio美化
    nodejs-微信公众号 ----答疑机器人
    微信小程序----开发小技巧(二)
  • 原文地址:https://www.cnblogs.com/HexQwQ/p/13395272.html
Copyright © 2011-2022 走看看