Preprocessor Solution

Sort by

recency

|

188 Discussions

|

  • + 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 ="
    
  • + 0 comments

    This has to be the worst defined problem that I had ever solved. Literally.