编译命令
(NOI)Linux
- 在
~/.bashrc 末尾添加:
Bashcpl() {
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 -e "\e[32mCompiled ./$1.cpp\e[0m"
}
run() {
cpl "$1" && echo -e "\e[36mRunning ./$1\n---------------begin---------------\e[0m" && local TIMEFORMAT=$'\e[33m\n----------------end----------------\nTime: %3Rs\e[0m' && time "./$1"
}
- 可在控制台内运行如下命令以重新加载
~/.bashrc 中的命令:
Bashsource ~/.bashrc
Windows
- 在(VSCode 中的)Powershell 内运行(用户名不是
Administrator 的自行改为实际用户名):
Bashcd C:\Users\Administrator\Documents
mkdir .\WindowsPowerShell
cd .\WindowsPowerShell
type nul > Microsoft.VSCode_profile.ps1
type nul > Microsoft.PowerShell_profile.ps1
code Microsoft.VSCode_profile.ps1
code Microsoft.PowerShell_profile.ps1
- 在打开的文件中添加:
Bashfunction cpl {
param([string]$name)
$cppFile = ".\$name.cpp"
$exeFile = ".\$name.exe"
if (-not (Test-Path $cppFile)) {
Write-Error "Error: $cppFile not found"; return
}
Write-Host "Compiling $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" -ForegroundColor Yellow
}
}
function run {
param([string]$name)
cpl $name
if ($LASTEXITCODE -eq 0 -and (Test-Path ".\$name.exe")) {
Write-Host "Running .\$name.exe" -ForegroundColor Green
Write-Host "---------------begin---------------" -ForegroundColor Cyan
$swRun = [System.Diagnostics.Stopwatch]::StartNew()
& ".\$name.exe"
$swRun.Stop()
Write-Host "`n----------------end----------------" -ForegroundColor Yellow
Write-Host "Run Time: $($swRun.Elapsed.TotalSeconds.ToString('0.000')) s" -ForegroundColor Yellow
}
}
- 可在(VSCode 中的)Powershell 内运行如下命令以重新加载 PowerShell 配置文件:
Bash. $PROFILE
- 在部分特殊情况下,可以使用丐版命令来编译运行(将
$name 的值替换为程序实际路径并去掉 .cpp 即可):
Bash$name = ".\"; Write-Host "Compiling $name.cpp" -ForegroundColor Green; $swCompile = [System.Diagnostics.Stopwatch]::StartNew(); g++ "$name.cpp" -o "$name.exe" -O2 -std=gnu++14 -static -Wall -Wextra -Wshadow -Wno-unused-result "-Wl,--stack=1000000000" -DLOCAL; $swCompile.Stop(); Write-Host "Compile Time: $($swCompile.Elapsed.TotalSeconds.ToString('0.000')) s" -ForegroundColor Yellow; Write-Host "Running $name.exe" -ForegroundColor Green; Write-Host "---------------begin---------------" -ForegroundColor Cyan; $swRun = [System.Diagnostics.Stopwatch]::StartNew(); & "$name.exe"; $swRun.Stop(); Write-Host "`n----------------end----------------" -ForegroundColor Yellow; Write-Host "Run Time: $($swRun.Elapsed.TotalSeconds.ToString('0.000')) s" -ForegroundColor Yellow
配置文件
VSCode cpp.json
JSON "C++ Template": {
"prefix": "#cpp",
"body": [
"#include <bits/stdc++.h>",
"using namespace std;",
"#define int long long",
"#define ull unsigned long long",
"#define i128 __int128",
"#define ld long double",
"#define eb emplace_back",
"#define mt make_tuple",
"#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",
" #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() {",
" }",
"}",
"signed main() {",
" // freopen(\".in\", \"r\", stdin);",
" // freopen(\".out\", \"w\", stdout);",
" W_C_B_H::main();",
" return 0;",
"}"
],
"description": "C++ 缺省源"
}
VSCode settings.json
JSON{
"C_Cpp.errorSquiggles": "disabled",
"files.autoSave": "onWindowChange",
"editor.fontSize": 16,
"editor.renderWhitespace": "boundary",
"editor.wordWrap": "on"
}
Dev-C++ 缺省源
C++#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ull unsigned long long
#define i128 __int128
#define ld long double
#define eb emplace_back
#define mt make_tuple
#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
#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() {
}
}
signed main() {
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
W_C_B_H::main();
return 0;
}