下msys2
下载名字类似msys2-x86_64-日期.exe的exe。
下载完后安装并启动ucrt64的终端。
输入(Shift+Insert):
sed -i "s#https\?://mirror.msys2.org/#https://mirrors.tuna.tsinghua.edu.cn/msys2/#g" /etc/pacman.d/mirrorlist*
pacman -Syy
pacman -S mingw-w64-ucrt-x86_64-gcc再输入:
pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain按回车接受默认的全部安装,遇到 Y/n 输入 Y 。
- Win + R → 输入
sysdm.cpl→ 回车 - “高级” → “环境变量”
- 在”系统变量”里找
Path→ 编辑 - 新建一条,填入:
C:\msys64\ucrt64\bin - 用”上移”把它移到最顶上(压过 TDM-GCC 那条)
- 确定保存
配vscode
安装vscode。
下载插件:
- c/c++
- Chinese (Simplified) (简体中文) Language Pack for Visual Studio Code
- OI File Checker
- background
然后在项目文件夹下新建 .vscode 文件夹,在里面创建三个配置文件。
c_cpp_properties.json(IntelliSense 配置)
{
"configurations": [
{
"name": "UCRT64",
"compilerPath": "C:\\msys64\\ucrt64\\bin\\gcc.exe",
"intelliSenseMode": "gcc-x64",
"includePath": ["${workspaceFolder}/**"],
"cStandard": "c17",
"cppStandard": "c++17"
}
],
"version": 4
}tasks.json(编译任务)
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\msys64\\ucrt64\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-std=c++17"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
]
}launch.json(调试配置)
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++: g++.exe build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\msys64\\ucrt64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}代码片段新建cpp.json
{
"cpp": {
"prefix": "cpp",
"body": [
"#include<bits/stdc++.h>",
"using namespace std;",
"#define ull unsigned long long",
"#define ll long long",
"#define FOR(i,a,b) for(int i=(a);i<=(int)b;i++)",
"#define ROF(i,a,b) for(int i=(b);i>=(int)a;i--)",
"const int N=1e5+10;",
"const ll inf=1e18+10;",
"const ll mod=1e9+7;",
"const double eps=1e-7;",
"using Vl=vector<int>;",
"using PI=array<ll,2>;",
"namespace fast_IO {",
"#define IOSIZE 100000",
"\tstatic unsigned int precision = 6, POW[10] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000};\t// 向下取整到小数点后第 precision 位",
"\tstatic char obuf[IOSIZE], *p3 = obuf;",
"#ifdef ONLINE_JUDGE",
"\tstatic char ibuf[IOSIZE], *p1 = ibuf, *p2 = ibuf;",
"#define getchar() ((p1==p2)and(p2=(p1=ibuf)+fread(ibuf,1,IOSIZE,stdin),p1==p2)?(EOF):(*p1++))",
"#endif",
"#define putchar(x) ((p3==obuf+IOSIZE)&&(fwrite(obuf,p3-obuf,1,stdout),p3=obuf),*p3++=x)",
"\tinline int64_t read() { int64_t s = 0; int w = 1; char ch; while (ch = getchar(), !(ch>47 and ch<58) and (ch != EOF)) if (ch == '-') w = -1; if (ch == EOF) return false; while ((ch>47 and ch<58)) s = s * 10 + ch - 48, ch = getchar(); return s * w; }",
"\ttemplate<typename T> static inline bool read(T &s) { s = 0; int w = 1; char ch; while (ch = getchar(), !(ch>47 and ch<58) and (ch != EOF)) if (ch == '-') w = -1; if (ch == EOF) return false; while ((ch>47 and ch<58)) s = s * 10 + ch - 48, ch = getchar(); return s *= w, true; }",
"\ttemplate<typename T> static inline void print(T x) { if (x < 0) putchar('-'), x = -x; if (x > 9) print(x / 10); putchar(x % 10 + 48); }",
"\tstatic inline bool read(char &s) { while (s = getchar(), isspace(s) and s != EOF); return s != EOF; }",
"\tstatic inline void print(char x) { putchar(x); }",
"\tstatic inline bool read(char *s) { char ch; while (ch = getchar(), (ch<33) && ch != EOF); if (ch == EOF) return false; while (!(ch<33) and (ch != EOF)) *s++ = ch, ch = getchar(); *s = '\\0'; return true; }",
"\tstatic inline void print(char *x) { while (*x) putchar(*x++); }",
"\tstatic inline void print(const char *x) { for (int i = 0; x[i]; i++) putchar(x[i]); }",
"\tstatic inline bool read(std::string& s) { s = \"\"; char ch; while (ch = getchar(), (ch<33) and ch != EOF); if (ch == EOF) return false; while (!(ch<33)) s += ch, ch = getchar(); return true; }",
"\tstatic inline void print(std::string x) { for (int i = 0, n = x.size(); i < n; i++) putchar(x[i]); }",
"\tstatic inline bool read(bool &b) { char ch; while(ch=getchar(), (ch<33) and ch != EOF); return ch == EOF ?false :(b=ch^48, true); }",
"\tstatic inline void print(bool b) { putchar(b+48); }",
"\tstatic inline bool read(double &x) { char ch = getchar(); int f = 1; for(; (ch<48 or 57<ch) and (ch != EOF); ch=getchar()) if(ch == '-') f = -1; if(ch == EOF) return false; for(x=0; 47<ch and ch<58; ch=getchar()) x = x*10 + (ch^48); if(ch != '.') return x *= f, true; double y = 0.1; for(ch=getchar(); 47<ch and ch<58; ch=getchar()) x += y*(ch^48), y /= 10; return x *= f, true; }",
"\tstatic inline void print(double x) { if(x < 0) putchar('-'), x = -x; if(!precision) print((unsigned long long)(x-(unsigned long long)(x)>=0.5 ?x+1 :x)); else { unsigned long long xx = x; double y = ((x-xx)*POW[precision]); unsigned long long yy = (y-(unsigned long long)(y)>=0.5 ?y+1 :y); if(yy == POW[precision]) xx++, yy = 0; print(xx), putchar('.'); for(int j=precision-1; ~j; j--) putchar(48+yy/POW[j]%10); } }",
"\ttemplate<typename T, typename... T1> static inline int read(T& a, T1&... other) { return read(a) + read(other...); }",
"\ttemplate<typename T, typename... T1> static inline void print(T a, T1... other) { print(a), print(other...); }",
"\tstatic struct Fast_IO {",
"\t\tbool flag = 1;",
"\t\tinline ~Fast_IO() { fwrite(obuf, p3 - obuf, 1, stdout); }",
"\t\tinline void SetPrecision(int x) { if(x > 9) throw runtime_error(\"Precision too high!\"); else if(x < 0) throw runtime_error(\"Precision too low!\"); else precision = x; } // 浮点数精度设为 x,即精确到小数点后 x 位。",
"\t\tinline operator bool() { return flag; }",
"\t} io;",
"\tFast_IO& operator >> (Fast_IO &io, char *b) { return io.flag &= read(b), io; }",
"\ttemplate<typename T> static Fast_IO& operator >> (Fast_IO &io, T &b) { return io.flag &= read(b), io; }",
"\ttemplate<typename T> static Fast_IO& operator << (Fast_IO &io, T b) { return print(b), io; }",
"#define cout io",
"#define cin io",
"#define endl '\\n'",
"} using namespace fast_IO;",
"",
"int main(){",
"// freopen(\".in\",\"r\",stdin);",
"// freopen(\".out\",\"w\",stdout);",
"// ios::sync_with_stdio(0);",
"// cin.tie(0);cout.tie(0);",
" ",
" return 0;",
"}"
]
}
}打开setting.json,复制:
{
"workbench.colorTheme": "Dark Modern",
"editor.cursorBlinking": "smooth",
"editor.cursorSmoothCaretAnimation": "on",
"editor.smoothScrolling": true,
"background.fullscreen": {
"images": [
"https://gss0.baidu.com/9vo3dSag_xI4khGko9WTAnF6hhy/zhidao/pic/item/2cf5e0fe9925bc31c5e9cfde58df8db1ca1370c4.jpg"
],
"opacity": 0.9,
"size": "cover",
"position": "center",
"interval": 0,
"random": false
},
"oi-file-checker.setCompilerArgs": "-Wl,--stack=1022483648 -static -std=c++14"
}浏览器插件
先下篡改猴,然后添加脚本
// ==UserScript==
// @name Vscode 交互插件
// @namespace http://tampermonkey.net/
// @version 0.12
// @match https://www.luogu.com.cn/problem/*
// @match https://codeforces.com/problemset/problem/*/*
// @match https://codeforces.com/contest/*/problem/*
// @match https://atcoder.jp/*
// @match https://vjudge.net/*
// @include /^https:\/\/zhengruioi\.com\/problem\/\d+(\?.*)?$/
// @grant GM_xmlhttpRequest
// ==/UserScript==
(function() {
'use strict';
// 工具函数:创建悬浮按钮
function createFloatingButton(text, onClick, buttonId) {
if (document.getElementById(buttonId)) return; // 防止重复
const btn = document.createElement('button');
btn.id = buttonId;
btn.textContent = text;
btn.style.cssText = `
position: fixed;
bottom: 20px;
right: 20px;
z-index: 9999;
padding: 10px 18px;
background: #3498db;
color: #fff;
border: none;
border-radius: 6px;
font-size: 14px;
cursor: pointer;
box-shadow: 0 2px 8px rgba(0,0,0,0.2);
`;
btn.addEventListener('click', onClick);
document.body.appendChild(btn);
}
/* ========== 洛谷 ========== */
function addLgButton() {
// 悬浮按钮代替原有插入逻辑
createFloatingButton('发送样例至 Vscode', () => {
const codes = Array.from(document.querySelectorAll('pre.lfe-code')).map(el => el.innerText);
const url = location.href;
if (/^https:\/\/www\.luogu\.com\.cn\/problem\//.test(url) && !url.endsWith("#submit")) {
GM_xmlhttpRequest({
method: "POST",
url: "http://127.0.0.1:4000/send",
headers: { "Content-Type": "application/json" },
data: JSON.stringify({ samples: codes }),
onload: res => alert('发送成功'),
onerror: err => alert('发送失败')
});
} else {
alert('请回到题面再发送数据');
}
}, 'lg-send-btn');
// 原toast代码仍然可以保留,这里改用简单alert,如需可自行替换回showSuccessToast/showErrorToast
// (原toast函数此处省略,实际使用时可保留并调用)
}
/* ========== Codeforces ========== */
function addCfButton() {
if (document.getElementById("cf-send-btn")) return;
function fadeOutAndRemove(el) {
el.style.transition = "opacity 1s";
el.style.opacity = "0";
setTimeout(() => { if (el.parentNode) el.parentNode.removeChild(el); }, 800);
}
function show(msg) {
let container = document.querySelector("#jGrowl.bottom-right.jGrowl");
if (!container) {
container = document.createElement("div");
container.id = "jGrowl";
container.className = "bottom-right jGrowl";
const emptyNotification = document.createElement("div");
emptyNotification.className = "jGrowl-notification";
container.appendChild(emptyNotification);
document.body.appendChild(container);
}
const notification = document.createElement("div");
notification.className = "jGrowl-notification default";
notification.style.display = "block";
notification.style.opacity = "0.8";
notification.innerHTML = `
<div class="close">×</div>
<div class="header"></div>
<div class="message">${msg}</div>
`;
notification.querySelector(".close").addEventListener("click", () => fadeOutAndRemove(notification));
container.appendChild(notification);
setTimeout(() => fadeOutAndRemove(notification), 5000);
}
const sidebar = document.getElementById("sidebar");
if (!sidebar) return;
const box = document.createElement("div");
box.className = "roundbox sidebox borderTopRound";
box.innerHTML = `
<div class="caption titled">
→ 复制数据到 VsCode
<div class="top-links"></div>
</div>
<div style="text-align:center;margin:1em;">
<button id="cf-send-btn">发送</button>
</div>
`;
sidebar.insertBefore(box, sidebar.firstChild);
document.getElementById("cf-send-btn").addEventListener("click", () => {
const samples = [];
document.querySelectorAll(".sample-test").forEach(block => {
const inputs = block.querySelectorAll(".input pre");
const outputs = block.querySelectorAll(".output pre");
inputs.forEach((inputEl, i) => {
const outputEl = outputs[i];
if (outputEl) {
samples.push(inputEl.innerText.trim());
samples.push(outputEl.innerText.trim());
}
});
});
GM_xmlhttpRequest({
method: "POST",
url: "http://127.0.0.1:4000/send",
headers: { "Content-Type": "application/json" },
data: JSON.stringify({ samples: samples }),
onload: res => show('发送成功'),
onerror: err => show('发送失败')
});
});
}
/* ========== AtCoder ========== */
function addAtButton() {
if (!document.getElementById("task-statement")) return;
if (document.getElementById("at-send-btn")) return;
const col = Array.from(document.querySelectorAll("div.col-sm-12"))
.find(div => div.id !== "contest-nav-tabs");
if (!col) return;
const spanH2 = col.querySelector("span.h2");
if (!spanH2) return;
const btn = document.createElement("button");
btn.id = "at-send-btn";
btn.className = "btn btn-default btn-sm send-to-vscode-btn";
btn.textContent = "发送数据至 VsCode";
spanH2.appendChild(btn);
btn.addEventListener("click", () => {
const samples = [];
document.querySelectorAll("section").forEach(section => {
const h3 = section.querySelector("h3");
if (h3?.textContent.includes("Sample")) {
const text = section.querySelector("pre")?.textContent.trim();
samples.push(text);
}
});
GM_xmlhttpRequest({
method: "POST",
url: "http://127.0.0.1:4000/send",
headers: { "Content-Type": "application/json" },
data: JSON.stringify({ samples: samples })
});
});
}
/* ========== Vjudge(改为悬浮按钮) ========== */
function addVjButton() {
createFloatingButton('发送数据至 VsCode', () => {
let iframe;
if (document.getElementById("frame-description")) {
iframe = document.getElementById("frame-description");
} else if (document.getElementById("frame-description-container")) {
const iframes = document.getElementById("frame-description-container").querySelectorAll("iframe");
iframe = Array.from(iframes).find(f => window.getComputedStyle(f).display !== "none");
}
if (!iframe) {
alert('未找到题目描述 iframe,请确认页面加载完成');
return;
}
const innerDoc = iframe.contentDocument || iframe.contentWindow.document;
const samples = [];
const container = innerDoc.getElementById("description-container");
if (container) {
container.querySelectorAll("table.vjudge_sample tbody tr td pre").forEach(section => {
samples.push(section.textContent.trim());
});
}
GM_xmlhttpRequest({
method: "POST",
url: "http://127.0.0.1:4000/send",
headers: { "Content-Type": "application/json" },
data: JSON.stringify({ samples: samples })
});
}, 'vj-send-btn');
}
/* ========== 正睿(改为悬浮按钮) ========== */
function addZrButton() {
createFloatingButton('发送数据至 VsCode', () => {
const samples = [];
document.querySelectorAll("h3").forEach(h3 => {
if (h3?.textContent.includes("样例") && (h3?.textContent.includes("输入") || h3?.textContent.includes("输出"))) {
const pre = h3.nextElementSibling;
const text = pre?.querySelector("pre")?.textContent.trim();
if (text) samples.push(text);
}
});
GM_xmlhttpRequest({
method: "POST",
url: "http://127.0.0.1:4000/send",
headers: { "Content-Type": "application/json" },
data: JSON.stringify({ samples: samples })
});
}, 'zr-send-btn');
}
/* ========== 路由启动 ========== */
if (location.hostname.includes("luogu.com.cn")) {
const observer = new MutationObserver(() => addLgButton());
observer.observe(document.body, { childList: true, subtree: true });
addLgButton();
}
else if (location.hostname.includes("codeforces.com")) {
const observer = new MutationObserver(() => addCfButton());
observer.observe(document.body, { childList: true, subtree: true });
addCfButton();
}
else if (location.hostname.includes("atcoder.jp")) {
const observer = new MutationObserver(() => addAtButton());
observer.observe(document.body, { childList: true, subtree: true });
addAtButton();
}
else if (location.hostname.includes("vjudge.net")) {
const observer = new MutationObserver(() => addVjButton());
observer.observe(document.body, { childList: true, subtree: true });
addVjButton();
}
else if (location.hostname.includes("zhengruioi.com")) {
const observer = new MutationObserver(() => addZrButton());
observer.observe(document.body, { childList: true, subtree: true });
addZrButton();
}
})();之后管理扩展打开开发人员模式,再在篡改猴的详细设置中全部打勾。