Personally feel that single-step debugging trouble and cost time, so I two years of time F4+watch basic not how to use, but because "view variable value" This demand always exist, and debugging often need to show a lot of things, printf write up and compare egg pain, happen in C + + 11 know the variable parameter template This new thing, so decisive to come to write the debug code.
Local debugging, written in the header file, and then only the local containing it, OJ ignored. [Local.h] =
1 2 3 4 5 6 7 8 910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
#ifndef _local#define _localnamespace Debug { void print () { cout << Endl; } Template<TypeName T> void Print (Const T t) { cout << T << Endl; } Template<TypeName F, TypeName... R> void Print (Const F F, Const R...R) { cout << F << " "; print (R ...); } Template<TypeName T> void Print (T*p, T*q) { int D = P < Q ? 1 : -1; while(P != q) { cout << *P << ", "; P += D; } cout << Endl; } Template<TypeName T1, TypeName T2> void Print (Pair<T1, T2> x) { Print ("first =\"", X.first, "\"second =\"", X.second, "\""); }}class Timer {Private: clock_t _start; clock_t _end;Public : Timer () { start (); } void Start () { _start = clock (); } Double get () { _end = clock (); Double Usedtime = Double(_end - _start) / Clk_tck; cout << "Used time:" << Usedtime << 1\ n"; return Usedtime; }};#endif |
Header Files etc =
1 2 3 4 5 6 7 8 9101112131415161718192021222324 |
#include <bits/stdc++.h>using namespace std;#ifndef Online_judge #include "Local.h"#endif#define X First#define Y Second#define PB (x) push_back (x)#define MP (x, y) make_pair (x, y)#define ALL (a) (a). Begin (), (a). End ()#define MSET (A, X) memset (A, X, sizeof (a))#define MCPY (A, B) memcpy (A, B, sizeof (a))typedef Long Long ll;Template<TypeName T>BOOL Umax (T&A, Const T&b) {return b<=a?false:(A=b,true);}Template<TypeName T>BOOL Umin (T&A, Const T&C) {return b>=a?false:(A=b,true);}int Main () {#ifndef Online_judge Freopen ("In.txt", "R", stdin); //freopen ("OUT.txt", "w", stdout);#endif//Online_judge return 0;} |
Results:
Some header files and debug code for ACM