首页 > 代码库 > 【黑科技】读写优化

【黑科技】读写优化

读入优化:

inline int read(){    char ch;    bool flag = false;    int a = 0;    while(!((((ch = getchar()) >= 0) && (ch <= 9)) || (ch == -)));    if(ch != -)    {        a *= 10;        a += ch - 0;    }    else    {        flag = true;    }    while(((ch = getchar()) >= 0) && (ch <= 9))    {        a *= 10;        a += ch - 0;    }    if(flag)    {        a = -a;    }    return a;}

 

输出优化:

void write(int a){    if(a < 0)    {        putchar(-);        a = -a;    }    if(a >= 10)    {        write(a / 10);    }    putchar(a % 10 + 0);    putchar(\n);}