版本比较
一个 OIer 的编译命令 & 配置文件
标题
增加 1 行删除 1 行
11一个 OIer 的编译命令 & 缺省源文件一个 OIer 的编译命令 & 配置文件正文
增加 143 行删除 78 行
3 行未改动4567889910111112121314141516151617182 行未改动2122232427252629303127282930313233343536343738363940414243444546444546474849505152535455565758596061625354636465565766676869707172737475647677787968808182838485868788899091929394769596977980818298991001011021031041058586878889909192939495969798991001011061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391031041401411421071081091101431441451461471131481491501511521531191541551561571581591601611621631641651661671681691701221711721731251261271281741751761771781791801811311321331341351361371381391401411421431441451461471821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142151491502162172181531542192202212222232 行未改动3 行未改动
1. 在 `~/.bashrc` 末尾添加:
```bash line-numbers
cpl () { g++ "./$1.cpp" -o "./$1" -O2 -std=c++14 -static -Wall -Wextra && echo "Compiled ./$1.cpp"cpl() { g++ "./$1.cpp" -o "./$1" -O2 -std=gnu++14 -static -Wall -Wextra -Wshadow -Wno-unused-result -Wno-sign-compare -Wl,-z,stack-size=1000000000 -fsanitize=undefined,bounds -DLOCAL && echo "Compiled ./$1.cpp"}run () { cpl "$1" && echo -e "Running ./$1\n" && time "./$1"run() { cpl "$1" && echo -e "Running ./$1\n--------------------------------" && time "./$1"}zp() { zip -r "./$1.zip" "./$1" && echo "Compressed folder ./$1"}```
2. 可在控制台内运行如下命令以重新加载 `~/.bashrc` 中的命令:
2 行未改动```
### Windows
1. 在(VSCode 中的)Powershell 内运行:1. 在(VSCode 中的)Powershell 内运行(用户名不是 `Administrator` 的自行改为实际用户名):
```powershell line-numbersNew-Item -Path $PROFILE -Type File -Forcecode $PROFILE```bash line-numberscd C:\Users\Administrator\Documentsmkdir .\WindowsPowerShellcd .\WindowsPowerShelltype nul > Microsoft.VSCode_profile.ps1type nul > Microsoft.PowerShell_profile.ps1code Microsoft.VSCode_profile.ps1code Microsoft.PowerShell_profile.ps1```
2. 在打开的 `Microsoft.VSCode_profile.ps1` 中添加:2. 在打开的文件中添加:
```powershell line-numbers```bash line-numbersfunction cpl { param([string]$name) $cppFile = ".\$name.cpp" $exeFile = ".\$name.exe" if (-not (Test-Path $cppFile)) { Write-Error "Error: $cppFile not found"; return } g++ "$cppFile" -o "$exeFile" -O2 -std=c++14 -static -Wall -Wextra if ($LASTEXITCODE -eq 0) { Write-Host "Compiled $cppFile" -ForegroundColor Green $swCompile = [System.Diagnostics.Stopwatch]::StartNew() g++ "$cppFile" -o "$exeFile" -O2 -std=gnu++14 -static -Wall -Wextra -Wshadow -Wno-unused-result -Wno-sign-compare "-Wl,--stack=1000000000" -DLOCAL # 神秘 Windows 没法加 "-fsanitize=undefined,bounds" $swCompile.Stop() if ($LASTEXITCODE -eq 0) { Write-Host "Compile Time: $($swCompile.Elapsed.TotalSeconds.ToString('0.000')) s" }}
function run { param([string]$name) cpl $name if ($LASTEXITCODE -eq 0 -and (Test-Path ".\$name.exe")) { Write-Host "Running .\$name.exe`n" -ForegroundColor Cyan $sw = [System.Diagnostics.Stopwatch]::StartNew() Write-Host "--------------------------------" $swRun = [System.Diagnostics.Stopwatch]::StartNew() & ".\$name.exe" $sw.Stop() Write-Host "`nTime: $($sw.Elapsed.TotalSeconds.ToString('0.000')) s" -ForegroundColor Yellow $swRun.Stop() Write-Host "`n--------------------------------" Write-Host "Run Time: $($swRun.Elapsed.TotalSeconds.ToString('0.000')) s" }}
```
3. 可在(VSCode 中的)Powershell 内运行如下命令以重新加载 PowerShell 配置文件:
```powershell line-numbers```bash line-numbers. $PROFILE```
## 缺省源文件4. 在部分特殊情况下,可以使用丐版命令来编译运行(将 `$name` 的值替换为程序实际路径并去掉 `.cpp` 即可):
```bash line-numbers$name = ".\"; $swCompile = [System.Diagnostics.Stopwatch]::StartNew(); g++ "$name.cpp" -o "$name.exe" -O2 -std=gnu++14 -static -Wall -Wextra -Wshadow -Wno-unused-result -Wno-sign-compare "-Wl,--stack=1000000000" -DLOCAL; $swCompile.Stop(); if ($LASTEXITCODE -eq 0) { echo "Compile Time: $($swCompile.Elapsed.TotalSeconds.ToString('0.000')) s" ; echo --------------------------------; $swRun = [System.Diagnostics.Stopwatch]::StartNew(); & "$name.exe"; $swRun.Stop(); echo `n--------------------------------; echo "Run Time: $($swRun.Elapsed.TotalSeconds.ToString('0.000')) s" }```
## 配置文件
### VSCode `cpp.json`
```json line-numbers
"C++ Template": { "prefix": "#cpp", "body": [ "#include<bits/stdc++.h>", "#include <bits/stdc++.h>", "using namespace std;", "#define int long long", "#define ull unsigned long long", "#define pb push_back", "#define pii pair<int,int>", "#define p3i pair<int,pii>", "#define i128 __int128", "using ull = unsigned long long;", "using ld = long double;", "using pii = pair<int, int>;", "using p3i = pair<int, pii>;", "#define eb emplace_back", "#define fi first", "#define se second", "#define all(a) (a).begin(),(a).end()", "const int inf=0x3f3f3f3f, llinf=0x3f3f3f3f3f3f3f3f;", "namespace IO", "{", " bool read(int &x){ x=0; char c=getchar(); bool f=0; while(!isdigit(c)){ f|=(c=='-'); if(c==EOF) return 0; c=getchar(); }", " while(isdigit(c)){ x=(x<<3)+(x<<1)+(c^48); c=getchar(); } if(f) x=-x; return 1; }", " bool read(string &s){ s=\"\"; char c=getchar(); while(!isprint(c) || isspace(c)){ if(c==EOF) return 0; c=getchar(); }", " while(isprint(c) && !isspace(c)){ s+=c; c=getchar(); } return 1; }", " bool read(char &c){ c=getchar(); while(!isprint(c) || isspace(c)){ if(c==EOF) return 0; c=getchar(); } return 1; }", " template<typename T,typename... U> bool read(T &x,U&... y){ if(!read(x)) return 0; return read(y...); }", " void write(int x){ if(x<0){ putchar('-'); x=-x; } string s=\"\"; do{ s+=x%10^48; x/=10; }while(x); reverse(all(s)); for(char c:s) putchar(c); }", " void write(char c){ putchar(c); } void write(const char *s){ while(*s) putchar(*s++); } void write(string x){ for(char c:x) putchar(c); }", " template<typename T,typename... U> void write(T x,U... y){ write(x); write(y...); }", " template<typename T,typename... U> void writeln(T x,U... y){ write(x,y...); puts(\"\"); }", "}", "namespace W_C_B_H", "{", "#define all(a) (a).begin(), (a).end()", "const int inf = 0x3f3f3f3f, Inf = 0x3f3f3f3f3f3f3f3f;", "template<typename T, typename U> void chkmin(T &x, U y) { x > y && (x = y); }", "template<typename T, typename U> void chkmax(T &x, U y) { x < y && (x = y); }", "", "char buf[1 << 20], *p1 = buf, *p2 = buf;", "#ifdef LOCAL", " #if defined(__linux__) || defined(__linux)", " #define gc getchar_unlocked", " #elif defined(_WIN32) || defined(_WIN64)", " #define gc _getchar_nolock", " #else", " #define gc getchar", " #endif", "#else", " #define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2) ? EOF : *p1++)", "#endif", "", "namespace IO { bool read(int &x) { x = 0; char c = gc(); bool f = 0; while (!isdigit(c)) { f |= c == '-';", "if (c == EOF) { return 0; } c = gc(); } while (isdigit(c)){ x = (x << 3) + (x << 1) + (c ^ 48); c=gc(); }", "if (f) { x=-x; } return 1; } bool read(string &s){ s = \"\"; char c=gc(); while (!isprint(c) || isspace(c))", "{ if (c == EOF) { return 0; } c = gc(); } while(isprint(c) && !isspace(c)){ s+=c; c = gc(); } return 1; }", "bool read(char &c) { c = gc(); while (!isprint(c) || isspace(c)){ if (c == EOF) { return 0; } c = gc(); }", "return 1; } template < typename T, typename U > bool read(pair<T, U> &x) { if (!read(x.fi)) { return 0; }", "return read(x.se); } template < typename T, typename ... U > bool read(T & x, U &... y) { if (!read(x)) {", "return 0; } return read(y...); } void write(int x) { if(x < 0){ putchar('-'); x = -x; } string s = \"\"; do", "{ s += x % 10 ^ 48; x /= 10; } while(x); for (int i = s.size() - 1; ~i; i--) putchar(s[i]); } void write(", "char c) { putchar(c); } void write(const char *s) { while(*s) putchar(*s++); } void write(string x) { for", "(char c : x) putchar(c); } template <typename T, typename... U> void write(T x, U... y) { write(x); write", "(y...); } template <typename T, typename U> void write(pair <T, U> &x) { write(x.fi); putchar(' '); write", "(x.se); } template <typename T, typename... U> void writeln(T x, U ... y) { write(x, y...); puts(\"\"); } }", "", "namespace W_C_B_H {", " using namespace IO;", " void main()", " {", " void main() {", " }", "}", "signed main()", "{", " // freopen(\".in\",\"r\",stdin);", " // freopen(\".out\",\"w\",stdout);", "signed main() {", " // freopen(\".in\", \"r\", stdin);", " // freopen(\".out\", \"w\", stdout);", " W_C_B_H::main();", " return 0;", "}", "}" ], "description": "C++ 缺省源" }```
### Dev-C++### VSCode `settings.json`
```json line-numbers{ "C_Cpp.errorSquiggles": "disabled", "files.autoSave": "onFocusChange", "editor.fontSize": 16, "editor.renderWhitespace": "boundary", "editor.wordWrap": "on" "workbench.colorTheme": "Quiet Light", "editor.trimAutoWhitespace": false}```
### Dev-C++ 缺省源
```cpp line-numbers#include<bits/stdc++.h>#include <bits/stdc++.h>using namespace std;#define int long long#define ull unsigned long long#define pb push_back#define pii pair<int,int>#define p3i pair<int,pii>#define i128 __int128using ull = unsigned long long;using ld = long double;using pii = pair<int, int>;using p3i = pair<int, pii>;#define eb emplace_back#define fi first#define se second#define all(a) (a).begin(),(a).end()const int inf=0x3f3f3f3f, llinf=0x3f3f3f3f3f3f3f3f;namespace IO{ bool read(int &x){ x=0; char c=getchar(); bool f=0; while(!isdigit(c)){ f|=(c=='-'); if(c==EOF) return 0; c=getchar(); } while(isdigit(c)){ x=(x<<3)+(x<<1)+(c^48); c=getchar(); } if(f) x=-x; return 1; } bool read(string &s){ s=""; char c=getchar(); while(!isprint(c) || isspace(c)){ if(c==EOF) return 0; c=getchar(); } while(isprint(c) && !isspace(c)){ s+=c; c=getchar(); } return 1; } bool read(char &c){ c=getchar(); while(!isprint(c) || isspace(c)){ if(c==EOF) return 0; c=getchar(); } return 1; } template<typename T,typename... U> bool read(T &x,U&... y){ if(!read(x)) return 0; return read(y...); } void write(int x){ if(x<0){ putchar('-'); x=-x; } string s=""; do{ s+=x%10^48; x/=10; }while(x); reverse(all(s)); for(char c:s) putchar(c); } void write(char c){ putchar(c); } void write(const char *s){ while(*s) putchar(*s++); } void write(string x){ for(char c:x) putchar(c); } template<typename T,typename... U> void write(T x,U... y){ write(x); write(y...); } template<typename T,typename... U> void writeln(T x,U... y){ write(x,y...); puts(""); }}namespace W_C_B_H{#define all(a) (a).begin(), (a).end()const int inf = 0x3f3f3f3f, Inf = 0x3f3f3f3f3f3f3f3f;template<typename T, typename U> void chkmin(T &x, U y) { x > y && (x = y); }template<typename T, typename U> void chkmax(T &x, U y) { x < y && (x = y); }
char buf[1 << 20], *p1 = buf, *p2 = buf;#ifdef LOCAL #if defined(__linux__) || defined(__linux) #define gc getchar_unlocked #elif defined(_WIN32) || defined(_WIN64) #define gc _getchar_nolock #else #define gc getchar #endif#else #define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2) ? EOF : *p1++)#endif
namespace IO { bool read(int &x) { x = 0; char c = gc(); bool f = 0; while (!isdigit(c)) { f |= c == '-';if (c == EOF) { return 0; } c = gc(); } while (isdigit(c)){ x = (x << 3) + (x << 1) + (c ^ 48); c=gc(); }if (f) { x=-x; } return 1; } bool read(string &s){ s = ""; char c=gc(); while (!isprint(c) || isspace(c)){ if (c == EOF) { return 0; } c = gc(); } while(isprint(c) && !isspace(c)){ s+=c; c = gc(); } return 1; }bool read(char &c) { c = gc(); while (!isprint(c) || isspace(c)){ if (c == EOF) { return 0; } c = gc(); }return 1; } template < typename T, typename U > bool read(pair<T, U> &x) { if (!read(x.fi)) { return 0; }return read(x.se); } template < typename T, typename ... U > bool read(T & x, U &... y) { if (!read(x)) {return 0; } return read(y...); } void write(int x) { if(x < 0){ putchar('-'); x = -x; } string s = ""; do{ s += x % 10 ^ 48; x /= 10; } while(x); for (int i = s.size() - 1; ~i; i--) putchar(s[i]); } void write(char c) { putchar(c); } void write(const char *s) { while(*s) putchar(*s++); } void write(string x) { for(char c : x) putchar(c); } template <typename T, typename... U> void write(T x, U... y) { write(x); write(y...); } template <typename T, typename U> void write(pair <T, U> &x) { write(x.fi); putchar(' '); write(x.se); } template <typename T, typename... U> void writeln(T x, U ... y) { write(x, y...); puts(""); } }
namespace W_C_B_H { using namespace IO; void main() { void main() { }}signed main(){signed main() {// freopen(".in","r",stdin);// freopen(".out","w",stdout); W_C_B_H::main(); return 0;2 行未改动