版本比较
一个 OIer 的编译命令 & 配置文件
标题
增加 1 行删除 1 行
11一个 OIer 的编译命令 & 缺省源文件一个 OIer 的编译命令 & 配置文件正文
增加 94 行删除 62 行
123434567811129101114151213141718191516171824 行未改动4344454652535447484950515253545556575859606162616263636465656667666768697071727374757677787978808182818384858486878889903 行未改动94959697969899100101102103991001041051061071081091101111121081091101111131141151161171181191201131211221231241251261271281291301311321331341351361371161171181191201211221231241251261271381391401418 行未改动1501511521531441541551561571581591601611621631641651661671681691701711721731501741751761771781791531541801811821581831841851861871881621631641651891901911921931941951961671971981991701711721731741751761771781791802002012022032042052062072082092102112122132142152169 行未改动## 编译命令
`-Wno-unused-result` 是为了防止没有使用 `freopen` 的返回值从而产生警告。
### (NOI)Linux
1. 在 `~/.bashrc` 末尾添加:
```bash line-numbers
cpl () { g++ "./$1.cpp" -o "./$1" -O2 -std=gnu++14 -static -Wall -Wextra -Wshadow -Wno-unused-result -Wl,-z,stack-size=1000000000 -fsanitize=undefined,bounds && 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` 中的命令:
24 行未改动 $exeFile = ".\$name.exe" if (-not (Test-Path $cppFile)) { Write-Error "Error: $cppFile not found"; return } g++ "$cppFile" -o "$exeFile" -O2 -std=gnu++14 -static -Wall -Wextra -Wshadow -Wno-unused-result "-Wl,--stack=1000000000" # 神秘 Windows 没法加 "-fsanitize=undefined,bounds" 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" -ForegroundColor Cyan Write-Host "---------------begin---------------" -ForegroundColor Cyan $sw = [System.Diagnostics.Stopwatch]::StartNew() Write-Host "--------------------------------" $swRun = [System.Diagnostics.Stopwatch]::StartNew() & ".\$name.exe" $sw.Stop() Write-Host "`n----------------end----------------" -ForegroundColor Yellow Write-Host "Time: $($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 配置文件:
```bash line-numbers. $PROFILE```
4. 在部分特殊情况下,可以使用丐版命令来编译运行(将 `$name` 的值替换为程序实际路径即可):4. 在部分特殊情况下,可以使用丐版命令来编译运行(将 `$name` 的值替换为程序实际路径并去掉 `.cpp` 即可):
```bash line-numbers$name = ".\"; g++ "$name.cpp" -o "$name.exe" -O2 -std=gnu++14 -static -Wall -Wextra -Wshadow -Wno-unused-result "-Wl,--stack=1000000000"; Write-Host "Compiled $name.cpp" -ForegroundColor Green; Write-Host "Running $name.exe" -ForegroundColor Cyan; Write-Host "---------------begin---------------" -ForegroundColor Cyan; $sw = [System.Diagnostics.Stopwatch]::StartNew(); & "$name.exe"; $sw.stop(); Write-Host "`n----------------end----------------" -ForegroundColor Yellow; Write-Host "Time: $($sw.Elapsed.TotalSeconds.ToString('0.000')) s" -ForegroundColor Yellow$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-numbers3 行未改动 "body": [ "#include <bits/stdc++.h>", "using namespace std;", "#define int long long", "#define ull unsigned long long", "#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 pii pair<int, int>", "#define p3i pair<int, pii>", "#define fi first", "#define se second", "#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", " #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 getchar", " #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 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(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 {", " using namespace IO;", " void main() {", " }",8 行未改动 "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>using namespace std;#define int long long#define ull unsigned long long#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 pii pair<int, int>#define p3i pair<int, pii>#define fi first#define se second#define all(a) (a).begin(), (a).end()const int inf = 0x3f3f3f3f, llinf = 0x3f3f3f3f3f3f3f3f;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 #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 getchar #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(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(charc: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 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() {9 行未改动