HackerRank Solution: Preprocessor Solution

preview_player
Показать описание
HackerRank solution for Preprocessor Solution in C++. Learn how to use preprocessor directives. This is a tricky HackerRank challenge because the instructions and the code given are both unclear. However, if you learn how to define preprocessor macros, this coding challenge will become much easier.

Рекомендации по теме
Комментарии
Автор

Thank you for the tutorial. It's really helpful. I just have one question. 'io(vec)' will be replaced in the code with 'cin >> vec, ' and 'foreach(v, i)' will be replaced with 'for(int i=0; i<v.size(); i++)'? So, the code will look like this :

for(int i=0; i<v.size(); i++) {
cin >> v[i];
}

Is that correct?

radouanebouchou
Автор

Is #str a preprocessor directive? I didn't understand. What do you mean by "str" ? Also, there is no replacement for #define FUNCTION(a, b). Why? Thanks!

amruthaa
Автор

How could we change the definition of the keywords such as "if" and "endif", as we have done over here?

eruditionknow
Автор

why we use #define INF
instead of using const variable.

yogeshyts
Автор

#define io(vec) cin>>vec
// it only take's input, but how it stores input's in vector?

morshedraiankhan
Автор

//#define toStr(str) #str
//#define foreach(v, i) for(int i = 0 ; i < v.size() ; i++)
//#define FUNCTION(a, b)
//#define io(vec) cin >> vec
//#define minimum(a, b) a = (a < b) ? a : b
//#define maximum(a, b) a = (b > a) ? a : b
//#define INF 0

I have done the same code as you written but still, it's throwing a wrong answer

nikhilsingh
Автор

#define toStr(str) #str
#define foreach(v, i) for(int i = 0; i < v.size(); i++)
#define io(vec) cin >> vec
#define FUNCTION(a, b)
#define minimum (a, b) a = (a < b) ? a : b
#define maximum (a, b) a = (b < a) ? a : b
#define INF 0
not working gives an error

yogeshsuryawanshi-mjs