Preprocessor Solution

Sort by

recency

|

189 Discussions

|

  • + 0 comments

    Nice explanation of preprocessor directives and macros! They make C++ code cleaner and more efficient when used properly. Understanding how they work is as important in programming as knowing your rights and responsibilities under Texas Constitutional Carry is in real life.

  • + 0 comments

    One of my favorite C++ problems here, although completely detached from reality! 😄 But you need to know the language to solve this unusual puzzle – it's not as insane as it might initially seem 🤓

    #define FUNCTION(name, op) \
        void name(int& acc, const int val) { \
            if (val op acc) acc = val; \
        }
    
    #define foreach(vec, idx) \
        for (size_t idx = 0; idx < vec.size(); ++idx) 
    
    #define INF \
        numeric_limits<int>::max();
    
    #define io(vec) \
        cin >> vec
    
    #define toStr(str) \
        #str
    
    #include <limits>
    
  • + 0 comments

    Here is Preprocessor solution in c++ - https://programmingoneonone.com/hackerrank-preprocessor-solution-in-cpp.html

  • + 0 comments

    Since I found the exercise a bit unnecessary, I made some shortcuts to avoid using variables in some places. My solution is:

    #define toStr(X) "Result ="
    
    #define io(VEC) cin >> VEC
    
    #define FUNCTION(FUNNAME, OP)                       \
            void FUNNAME(int &m, int num){                   \
                if (num OP m){                                            \
                    m = num;                                               \
                }                                                                 \
            }                                                                     \
    
    
    #define foreach(V, I) for(int I = 0; I < n; I++)
    
    #define INF 999999
    
  • + 0 comments
    #define foreach(arg1, arg2) for(int i = 0; i < n; i++)
    #define io(arg) cin >> v
    
    #define INF 100000000
    
    
    #define minimum(arg1, arg2) if(arg1 > arg2) arg1 = arg2;
    #define maximum(arg1, arg2) if(arg1 < arg2) arg1 = arg2;
    
    #define FUNCTION(arg1, arg2) //
    
    #define toStr(arg) "Result ="