📌  相关文章
📜  如何在Visual Studio Code for C ++中设置竞争性编程

📅  最后修改于: 2021-05-31 22:33:55             🧑  作者: Mango

GCC编译器安装

我们需要为Windows安装GCC编译器。 Linux已经安装了GCC。

安装步骤

1.Download and Install the MinGW for GCC compiler using this link.
2.Open Control Panel in your system and then select: System (Control Panel)
3.Click on the Advanced system settings
4.Click on Environment Variables. In the section System Variables, find the PATH environment variable 
  and select it. Click Edit.
5.In the Edit System Variable window, specify the value of the PATH environment variable.
6.Type "C:\MinGW\bin"  
7.Click OK.
8.Close all remaining windows by clicking OK.


图片供其他参考

重要扩展

1.Code Runner (By JunHan)---> To run the c++ code
2.C/C++ (By Microsoft)---> For intellisense and debugging
3.competitve-programming helper (By Divyanshu Agrawal) ---> Automatically Reads I/O for 
  codechef/codeforces


用户代码段/启动模板竞争编程与

下面是程序员使用的竞争性编程模板的示例。您可以根据自己的选择和喜好更改此模板:

C++
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include  
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
  
using namespace std;
  
typedef long long ll;
typedef long double ld;
typedef pair p32;
typedef pair p64;
typedef pair pdd;
typedef vector v64;
typedef vector v32;
typedef vector > vv32;
typedef vector > vv64;
typedef vector > vvp64;
typedef vector vp64;
typedef vector vp32;
ll MOD = 998244353;
double eps = 1e-12;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<> t;
    for(int it=1;it<=t;it++) {
     cout << "Case #" << it+1 << ": ";
        solve();
    }
    return 0;
}


Javascript
{
    "C++ Snippet": {
        "prefix": "gfg",
        "body": [
          "#pragma GCC optimize(\"Ofast\")",
          "#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma\")",
          "#pragma GCC optimize(\"unroll-loops\")",
          "#include   ",
          "#include ",
          "#include ",
          "#include ",
          "#include ",
          "#include ",
          "#include ",
          "#include ",
          "#include ",
          "#include ",
          "#include ",
          "#include ",
          "#include ",
          "#include ",
          "#include ",
          "#include ",
          "#include ",
          "#include ",
          " ",
          "using namespace std;",
          " ",
          "typedef long long ll;",
          "typedef long double ld;",
          "typedef pair p32;",
          "typedef pair p64;",
          "typedef pair pdd;",
          "typedef vector v64;",
          "typedef vector v32;",
          "typedef vector > vv32;",
          "typedef vector > vv64;",
          "typedef vector > vvp64;",
          "typedef vector vp64;",
          "typedef vector vp32;",
          "ll MOD = 998244353;",
          "double eps = 1e-12;",
          "#define forn(i,e) for(ll i = 0; i < e; i++)",
          "#define forsn(i,s,e) for(ll i = s; i < e; i++)",
          "#define rforn(i,s) for(ll i = s; i >= 0; i--)",
          "#define rforsn(i,s,e) for(ll i = s; i >= e; i--)",
          "#define ln \"\\n\"",
          "#define dbg(x) cout<<#x<<\" = \"<> t;",
          "    for(int it=1;it<=t;it++) {",
          "     cout << \"Case #\" << it+1 << \": \";",
          "        solve();",
          "    }",
          "    return 0;",
          "}"
        ],
        "description": "C++ Snippet"
      }
}


C++
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif


创建用户代码段/启动模板的步骤

1.Open VS Code and go to: 
  File > Preferences > User Snippets
2.Click on New Snippets
3.Type cpp.json((can be anything).json)(the name of snippet)
4.Delete all the default code
5.Paste the json code given below
  (dont copy above C++ code!!, json files are needed for user snippets in VS Code)


在C++文件中使用用户代码段/启动模板的步骤

1.Create a .cpp file(note: below snippet will only work once used in C++ file)
2.type the Snippet Trigger(look at "prefix" attribute in 3rd line of json file given below)
3.press tab or enter
  (the defalut prefix is set as gfg, you can alter it as per your need)


用户代码段的JSON代码

Java脚本

{
    "C++ Snippet": {
        "prefix": "gfg",
        "body": [
          "#pragma GCC optimize(\"Ofast\")",
          "#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma\")",
          "#pragma GCC optimize(\"unroll-loops\")",
          "#include   ",
          "#include ",
          "#include ",
          "#include ",
          "#include ",
          "#include ",
          "#include ",
          "#include ",
          "#include ",
          "#include ",
          "#include ",
          "#include ",
          "#include ",
          "#include ",
          "#include ",
          "#include ",
          "#include ",
          "#include ",
          " ",
          "using namespace std;",
          " ",
          "typedef long long ll;",
          "typedef long double ld;",
          "typedef pair p32;",
          "typedef pair p64;",
          "typedef pair pdd;",
          "typedef vector v64;",
          "typedef vector v32;",
          "typedef vector > vv32;",
          "typedef vector > vv64;",
          "typedef vector > vvp64;",
          "typedef vector vp64;",
          "typedef vector vp32;",
          "ll MOD = 998244353;",
          "double eps = 1e-12;",
          "#define forn(i,e) for(ll i = 0; i < e; i++)",
          "#define forsn(i,s,e) for(ll i = s; i < e; i++)",
          "#define rforn(i,s) for(ll i = s; i >= 0; i--)",
          "#define rforsn(i,s,e) for(ll i = s; i >= e; i--)",
          "#define ln \"\\n\"",
          "#define dbg(x) cout<<#x<<\" = \"<> t;",
          "    for(int it=1;it<=t;it++) {",
          "     cout << \"Case #\" << it+1 << \": \";",
          "        solve();",
          "    }",
          "    return 0;",
          "}"
        ],
        "description": "C++ Snippet"
      }
}

图片供其他参考

基本导航

选择突出显示的选项以创建新的代码段

“ type cpp.json”代码段的名称,它应该是一个json文件

擦除所有这些默认代码并粘贴给定的json代码

注意:在Prefix中,您必须使用个人选择词,例如,在这里我正在使用gfg 。这非常重要,因为这是在代码中调用模板的关键。

通过按CTRL + S保存此代码段。

打开一个新的cpp文件,并在前缀框中输入您写的前缀。(这里我用过gfg)。

Input.txt和Output.txt(竞争编程助手扩展)

所有编码站点都使用文件比较方法来检查答案。这意味着它们通过您的程序将输出存储在一个文本文件中并与实际答案文件进行比较。因此,您也应该这样做。您需要做的是创建一个文件夹,并在其中创建2个文件input.txt,output.txt。

首先创建三个必需的文件。一个包含您程序的cpp文件。一个文本文件input.txt和output.txt。确保所有三个文件都在同一目录中。我们需要将编辑器分为三个空间

  1. 主码空间 
  2. 输入空间
  3. 输出空间

屏幕设置步骤

1.Once your cpp program is open, go to View>Editor Layout>Two Columns
2.In the empty(right) column right click and choose Split down
3.In the top window, right click and click on open file, open input.txt from the dropdown.
4.Repeat the same process in the bottom window. 
5.Paste the c++ code at the end of post just inside the main method 


图片供其他参考

注意:在输入中进行任何更改时,请不要忘记在input.txt框中按ctrl + S进行保存。
注意:不要忘记在您的main()之后添加此代码

C++

#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif

如果您希望与行业专家一起参加现场课程,请参阅《 Geeks现场课程》和《 Geeks现场课程美国》。