竞赛模板·数据统计与IO(重定向版)

 
/*
    数据统计与IO 重定向版模板

    描述:本机测试用文件数据流重定向,一旦提交到比赛就自动“删除”重定向语句
*/
# define LOCAL
#include<stdio.h>
#include<time.h>

int main(){
#ifdef LOCAL
    freopen("data.in","r", stdin);
    freopen("data.out","w", stdout);

    clock_t  start_t,stop_t;//计时的时钟变量
    double dur_t;//中间计时

    start_t = clock();
    /*
    time():
        @function:获取当前的系统时间
        @return:time_t(本质:大整数)
        @significance:其值表示从CUT(Coordinated Universal Time)时间1970年1月1日00:00:00(称为UNIX系统的Epoch时间)到当前时刻的秒数.
    */
    printf("[LOCAL] Test LOCAL Define.\n");
#endif // LOCAL

    int x;
    while(scanf("%d", &x) == 1){//从文件内读取成功一个变量值
        printf("%d\n", x);//写入数据
    }
    printf("Hello world!");

#ifdef LOCAL
    stop_t = clock();
    dur_t = (double)(stop_t - start_t);

    printf("\n[TIME] start_t:%f", start_t);
    printf("\n[TIME] stop_t:%f", stop_t);
    printf("\n[TIME] during time:%f", dur_t);

    printf("\n[TIME] USE TIME:%ds", dur_t / CLOCKS_PER_SEC);
    /*
        常量CLOCKS_PER_SEC:表示一秒钟会有多少个时钟计时单元
    */
#endif // LOCAL
    return 0;
}

  

【参考文献】

  刘汝佳.算法竞赛入门经典 

猜你喜欢

转载自www.cnblogs.com/johnnyzen/p/9066183.html