暫時發現的重定向的意義:將測試數據儲存在某一特定文件中,每次運行程序時自動提取,
能節省大量從控制檯(console)輸入數據的時間,尤其是在搞定ACM題的時候。
#pragma warning(disable:4996) //此句直接跳過error C4996,可以使程序正常運行併成功重定向。
//錯誤 1 error C4996: 'freopen': This function or variable may be unsafe.
//Consider using freopen_s instead.
#include<stdio.h>
#define LOCAL //只有定義了LOCAL纔會編譯兩條freopen語句。
#define INF 1000000000
int main(void)
{
#ifdef LOCAL
freopen("data.txt", "r", stdin); //data.txt中含有測試數據,文件後綴爲.txt好處是方便修改測試數據;
//另外,data.txt文件應該與相應C的源代碼文件放在同一文件夾下。
freopen("dataout.txt", "w", stdout); //dataout.txt中含有程序運行結果,方便查看。
#endif
int x, n = 0, min = INF, max = -INF, s = 0;
while (scanf_s("%d", &x) == 1)
{
s += x;
if (x < min) min = x;
if (x>max) max = x;
}
n++;
printf("%d %d %.3f\n", min, max, (double)s / n);
getchar();
getchar();
return 0;
}