本地Leetcode运行和调试环境部署

本地Leetcode运行和调试环境部署

工具及要求

    vscode g+±10(能够使用#include<bits/stdc++.h>) 能够在vscode将c++代码跑起来 熟悉Linux命令

实施步骤

其实一共是三个文件:

    main.cpp :主体代码 input.txt : 模拟输入内容 output.txt : 模拟输出内容

main.cpp内容如下:

#include<bits/stdc++.h>
using namespace std;
class Solution {
public:
    int YourFunction(int n) {
    }
};

int main(){
    #ifndef ONLINE_JUDEG
    freopen("./input.txt", "r", stdin);
    freopen("./output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int x;
    cin >> x;
    Solution s;
    cout << s.YourFunction(x) << endl; 
    return 0;
}

结果Demo

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-BspiPAfP-1655447194705)(https://raw.githubusercontent.com/Yukun4119/BlogImg/main/img/Screen%20Shot%202021-08-14%20at%2016.39.41.png)]

技巧

可以用alias的方法快速构建该项目。

alias lctest="mkdir -p ~/Desktop/leetcode && cd ~/Desktop/leetcode && code input.txt output.txt demo.cpp"

这样在命令行中敲lctest就直接有上述项目。

然后利用vscode 的User Snippets去把main.cpp模板代码制作成自己的一个代码片段,方法请自行google,之后有时间会单独介绍代码片段的使用技巧。

Snippets使用示例:

经验分享 程序员 微信小程序 职场和发展