We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Preprocessor Solution
Preprocessor Solution
Sort by
recency
|
179 Discussions
|
Please Login in order to post a comment
C++
**#define INF 1000000
define minimum(a,b) a=(ausing ternary op/
define maximum(a,b) a=(a>b)?a:b
define foreach(v,i) for(int i=0;i
define io(v,i) cin>>v[i] /defining input/
define toStr(res) #res /*stringify operator-> # */
define FUNCTION(min_max, signal) void calc_##min_max(int& a, int b) {a = a signal b ? a : b;}
/*a is passed by ref while b is passed by val || calc_##min_max , concatenation operator in preprocessor->> '##' -> if signal is < then it becomes calc_minimum /*
include
include
using namespace std;
if !defined toStr || !defined io || !defined FUNCTION || !defined INF
error Missing preprocessor definitions
endifFUNCTION(minimum, <) FUNCTION(maximum, >)
int main(){ int n; cin >> n; vector v(n); **foreach(v, i) { io(v,i); ** /slightly modified as the prev given format was having few problem/ } int mn = INF; int mx = -INF; foreach(v, i) { minimum(mn, v[i]); maximum(mx, v[i]); } int ans = mx - mn; cout << toStr(Result =) <<' '<< ans; return 0;
}
foreach is missing in the problem template
next step use macros to implement a new programming language hehehe!