1. 程式人生 > 其它 >快讀快寫模版

快讀快寫模版

read(), write() \(<\) scanf(), printf() \(\approx\) ios::sync_with_stdio(0)+cin,cout \(<\) cin,cout
可見快讀快寫還是很厲害的
再加上 __int128 可以使用, 手寫讀入輸出就很重要了

#include <bits/stdc++.h>
#define re register
#define lll __int128    // NOIp 開放部分帶下劃線的東西啦
using namespace std;

// 快讀
lll read(){
    lll sign,num=0;
    char ch=getchar();
    while(ch<'0' || ch>'9'){
        if(ch=='-') sign=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9'){
        num=num*10+ch-'0';
        ch=getchar();
    }
    return num*sign;
}

// 快寫
void write(lll x){
    if(x<0){
        putchar('-');
        x=~x+1; // 相當於 x=-x
    }
    if(x>9) write(x/10);
    putchar(x%10+'0');
}

int main()
{
    ios::sync_with_stdio(0);
    clock_t c1 = clock();
#ifdef LOCAL
    freopen("data.in","r",stdin);
    freopen("data.out","w",stdout);
#endif
    // ======================================================================
    lll x=read();
    write(x);

    // ======================================================================
end:
    cerr << "Time Used:" << clock() - c1 << "ms" << endl;
    return 0;
}