You are on page 1of 1

05/10/2016

PreprocessorSolutionEditorial|C++Question|HackerRank

Domains

All Domains

Contests

Rank

Leaderboard

Jobs

Points: 95.00 Rank: 17458

C++ Introduction Preprocessor Solution

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

Problem Setter's code :

//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;
}

Join us on IRC at #hackerrank on freenode for hugs or bugs.


Contest Calendar | Blog | Scoring | Environment | FAQ | About Us | Support | Careers | Terms Of Service | Privacy Policy | Request a Feature

https://www.hackerrank.com/challenges/preprocessorsolution/editorial

1/1

You might also like