内容:
说明:
预处理的作用
示例代码:
// Preprocessor_Solution.cpp: 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <vector>
using namespace std;
#define toStr(x) #x
#define io(v) cin >> v
#define INF 100000000
#define foreach(v, i) for(int i = 0; i < v.size(); i++)
#define FUNCTION(name, op) void name(int& a, int b) { if (b op a) a = b; }
#if !defined toStr || !defined io || !defined FUNCTION || !defined INF
#error Missing preprocessor definitions
#endif
FUNCTION( minimum, < )
FUNCTION( maximum, > )
//by zhaocl
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;
}
知识点:
#define的使用,可以简单理解为编译时替换即可