Created
January 30, 2025 22:49
-
-
Save CompewterTutor/541f8440efdc3305f4f87c02cdd2e698 to your computer and use it in GitHub Desktop.
Leetcode C++ Debugging
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //// OUTPUT MACROS FOR DEBUGGING | |
| #define LINE0 9 | |
| #define cout_line (cout << "line " << __LINE__ - LINE0 << ": ") | |
| #define vout(v) #v << " = " << (v) | |
| #define print1(v) cout_line << vout(v) << endl | |
| #define print2(v1, v2) cout_line << vout(v1) << ", " << vout(v2) << endl | |
| #define print3(v1, v2, v3) cout_line << vout(v1) << ", " << vout(v2) << ", " << vout(v3) << endl | |
| #define print4(v1, v2, v3, v4) cout_line << vout(v1) << ", " << vout(v2) << ", " << vout(v3) << ", " << vout(v4) << endl | |
| #define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME | |
| #define print(...) GET_MACRO(__VA_ARGS__, print4, print3, print2, print1)(__VA_ARGS__) //COMMENT OUT BEFORE SUBMITTING | |
| //#define print(...) //UNCOMMENT BEFORE SUBMITTING | |
| template <class Ch, class Tr, class Container> | |
| basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x); | |
| template <class X, class Y> | |
| ostream & operator << (ostream & os, pair <X, Y> const& p) { | |
| return os << p.first << ":" << p.second; | |
| } | |
| template <class Ch, class Tr, class Container> | |
| basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) { | |
| os << "["; | |
| bool first = true; | |
| for(auto const& y : x) { | |
| if (!first) os << ", "; | |
| os << y; | |
| first = false; | |
| } | |
| return os << "]"; | |
| } | |
| //// CODE STARTS HERE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment