Professional Documents
Culture Documents
PreprocessorSolutionEditorial|C++Question|HackerRank
Domains
All Domains
Contests
Rank
Leaderboard
Jobs
Preprocessor Solution
by Dalimil
Problem
Submissions
Leaderboard
Discussions
Editorial
To complete this challenge, you must understand how #define and preprocessor directives work. You
can think of these as a set of instructions that the preprocessor checks for and follows before the
program is compiled.
Set by Dalimil
Statistics
Difficulty: Easy
Time Complexity: $O(n)$
Required Knowledge: Preprocessor,
Macros
Publish Date: Apr 14 2016
Originally featured in Code.cpp 4
//Samplesolution
#definetoStr(x)#x
#defineio(s)cin>>s
#defineforeach(list,index)for(intindex=0;index<list.size();index++)
#defineFUNCTION(name,op)voidname(int&x,inty){if(!(xopy))x=y;}
#defineINF1e9
/*Lockedfromheredown*/
#include<iostream>
#include<vector>
usingnamespacestd;
#if!definedtoStr||!definedio||!definedFUNCTION||!definedINF
#errorMissingpreprocessordefinitions
#endif
FUNCTION(minimum,<)
FUNCTION(maximum,>)
intmain(){
intn;cin>>n;
vector<int>v(n);
foreach(v,i){
io(v)[i];
}
intmn=INF;
intmx=INF;
foreach(v,i){
minimum(mn,v[i]);
maximum(mx,v[i]);
}
intans=mxmn;
cout<<toStr(Result=)<<''<<ans;
}
https://www.hackerrank.com/challenges/preprocessorsolution/editorial
1/1