[模板] Other

本文介绍了程序设计中常用的文件操作技巧,包括使用freopen进行文件重定向,通过系统调用执行外部程序,以及读写数据的优化方法。此外,还提供了一些常用的宏定义和计时器实现方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

文件操作

freopen("xx.in","r",stdin);
freopen("xx.out","w",stdout);

对拍

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
    int err=0,T=0;
    while(err!=1)
    {
        T++;
        system("data");
        system("bl");
        system("zj");
        error=system("fc bl.out zj.out");
        while(clock()<T*1000);
    }
} 
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <ctime>
using namespace std;
using namespace std;
int main()
{
    freopen("data.in","w",stdout);
    srand(time(0));
} 

读入、输出优化

int read(){
    char c=getchar();int x=0,f=1;
    while(c>'9'||c<'0') {
        if(c=='-') f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9') x=(x*10)+c-48,c=getchar();
    return x*f;
}

inline void out(int x)
{
    if(x>9) out(x/10);
    putchar(x%10+'0');
    putchar(32);
}

宏定义

#define M 100005
#define P 1000000007
#define INF 0x3f3f3f3f
#define INF INT_MAX
#define ll long long
#define fi first
#define se second
#define pii pair<int,int>
#define MP(a,b) make_pair(a,b)
const double eps=1e-9;
const double pi=acos(-1);
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

头文件模板

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <climits>
#include <algorithm>
#include <cmath>
#include <queue> 
#include <set> 
#include <stack> 
#include <map> 
#include <vector> 
#include <list>

简易版计时器


 int start = clock();
  //do_STH
  printf("%.3lf\n",double(clock()-start)/CLOCKS_PER_SEC);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值