C++输入输出优化

输入输出有时会被卡时间,所以我们可以通过一些例如getchar这样极快输入的方式减小提升我们输入输出的时间。

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cctype>
#include<cmath>
using namespace std;

inline int read()//输入
{
    int ret = 0,ret = 0; 
    char ch = 0;
    while(!isdigit(ch)) 
    {
        w |= ch == '-';
        ch = getchar();
    }
    while(isdigit(ch)) 
    {
        ret = (ret << 3) + (ret << 1) + (ch ^ 48);
        ch = getchar();
    }
    return w ? -ret : ret;
}
inline void write(int ret)//输出
{
     if(ret < 0)
     {
        putchar('-');
        x = -x;
     }  
     if(x > 9) 
        write(x / 10);
     putchar(x % 10 + '0');
}

猜你喜欢

转载自blog.csdn.net/ssl_TRX/article/details/81037963