介绍
在我们使用vscode时,我们会用到代码块。
代码块十分好用,可以帮我们自动补全代码,也可以存各种板子。虽然会损失人的代码能力,但能提升做题效率。但我们注意到,vscode的代码块是使用json
编辑的,对于不会json
的人就显得十分麻烦。而且,也不是把代码直接放上去就能用的,需要改各种格式,比如要很多'\'
,將缩进换成'\t'
,对于人类来说十分麻烦,而ai又过于繁忙并需要网络,所以可以写一个程序来实现自动转换。
用法
虽然程序开始时有提示,但我英语太垃圾了,写的东西可能以后看不懂。
第一行先输入先导句,及触发代码块补全所需写的东西(即触发条件),换一行,将要转换的代码复制上去,再换一行,打4个 '#'
即 "####"
表示代码部分结束。
程序会将转换好的文件打在文件 code.txt
,也可以手动更改生成的文件名。反正输出在哪里不重要,还是要复制出来粘贴到vscode对应的地方,而且应该没人不会 里面就是格式改好的代码块,直接复制即可。freopen
吧。
代码
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define usd unsigned
#define el cout << '\n'
#define lowbit(x) (x & (-x))
const int ranmod = 1e7;
#define random ((rand() * rand()) % ranmod)
#define AC return
#define AK return 0
#define YS cout << "YES"
#define NO cout << "NO"
#define Ys cout << "Yes"
#define No cout << "No"
#define ys cout << "yes"
#define no cout << "no"
#define ls(i) ch[i][0]
#define rs(i) ch[i][1]
#define debug(num) cerr << #num << ' ' << num << '\n'
// void init();
void main_();
signed main() {cout << "write prefix on the first line,write code below,(use \"####\" to end)"; el; // ios :: sync_with_stdio(false);// cin.tie(NULL);// cout.tie(NULL);// freopen(".in", "r", stdin);freopen("code.txt", "w", stdout);int t = 1;// cin >> t;while(t--) {// init();main_();}AK;
}
const int mod = 95225987, maxn = +18;string str;string solve(string s) {string res = "";int cnt = 0;while(s[cnt] == ' ' && cnt < s.length()) cnt++;for(int i = 1; i <= cnt / 4; i++) {res = res + '\\' + 't';}for(int i = cnt; i < s.length(); i++) {char ch = s[i];if(ch == '\"' || ch == '\'') {res += '\\';res += ch;} else if(ch == '\t') {res += '\\';res += 't';} else res += ch;}return res;
}void main_() {cout << "{" << '\n' << "\t\"include\": { \n\t\t\"prefix\": \""; getline(cin, str);cout << solve(str) << "\",\n";cout << "\t\t\"body\": ["; el;while(true) {getline(cin, str);if(str == "####") break;else {cout << "\t\t\t\"" << solve(str) << "\","; el;}}cout << "\t\t],\n";cout << "\t},\n}";el;
}