打算竞时最常见的就是(食大粪)调试。每个人都有自己的调试方式,至于单步调试速度实在有些慢,所以用的很少,所以我用的还是cout
cerr
居多,为了防止忘记所以来记录一下。
直接"===========\n"
从杨佬那学来的输出,各种变量分隔也很清晰。
cout<<"=========\n";
cout<<i<<' '<<q[i]<<'\n';
cerr输出
使用 cerr
在vscode中直接输出错误,cph中会将错误流单独输出,十分清晰。
debug.h
从某算竞群偷师学来的方法,操作较为麻烦
设置方法
将
debug
库放到 mingw64 依赖中
下面是debug.h文件具体内容,原文件都采用的是cout,我改成了cerr。
文件具体路径实例:
algo文件夹并不是必须的,可以直接放在外面D:\mingw64\lib\gcc\x86_64-w64-mingw32\8.1.0\include\c++\algo
D:\mingw64\lib\gcc\x86_64-w64-mingw32\8.1.0\include\c++\algo\debug.h#include<iostream> #include<time.h> using namespace std; void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} //clock_t ttt = clock(); //void __print(clock_t x) {cerr << int(x) << "ms";} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]"<<endl;} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #define debug(x...) cerr << #x << " = ["; _print(x) template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;} template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}
使用时在自己的模板中添加如下文件头
#ifdef LOCAL #include"algo/debug.h" #else #define debug(x) 42 #endif
这段代码的主要意思就是判断根据是否定义本地环境来设置是否include对应库
- 设置CPH
找到CPH拓展设置,添加-DLOCAL
,一般会自动保存。
使用效果展示
自动输出到错误流中,在评测机中这个 debug.h
并不会被包含。
交题记录