-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathpreprocessor-solution.cpp
More file actions
50 lines (39 loc) · 960 Bytes
/
preprocessor-solution.cpp
File metadata and controls
50 lines (39 loc) · 960 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Preprocessor Solution
// Create preprocessor macros to make the existing code work.
//
// https://www.hackerrank.com/challenges/preprocessor-solution/problem
//
#define INF 1000000000
#define FUNCTION(f, comp) \
void f(int& a, int b) \
{ if (b comp a) a = b; }
#define io(v) \
cin >> v
#define toStr(x) #x
#define foreach(v, i) \
for (size_t i = 0; i < v.size(); ++i)
// (skeliton_tail) ----------------------------------------------------------------------
#include <iostream>
#include <vector>
using namespace std;
#if !defined toStr || !defined io || !defined FUNCTION || !defined INF
#error Missing preprocessor definitions
#endif
FUNCTION(minimum, <)
FUNCTION(maximum, >)
int main(){
int n; cin >> n;
vector<int> v(n);
foreach(v, i) {
io(v)[i];
}
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;
}