救命的好习惯:快读快写

快读(详细注释)

//一般快读
//注意这个快读是非常的重要的,我想这应该是想要在OI这条路上走远的所有OIer必须会的东西,
//养成每次写题目都加上快读的好习惯,有可能会在关键的时候救你一命!
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
//可以换成#include
using namespace std;
inline int Read()
{
    int F=1,Num=0; //F是记录数字是否为负数,Num存储读入的数字
    char ch=getchar(); //getchar()读取一个字符
    while(ch<'0'||ch>'9') //isdigit()判断是否为数字
    {
        if(ch=='-') F=-1; //如果读入的字符是符号,标记F
        ch=getchar(); //继续读字符
    }
    while(ch>='0'&&ch<='9') //如果当前读入的字符是数字,则将整个数字全部读入
    {
        Num=Num*10+ch-'0'; //将读入的ASCII字符转换为数字
        //或者上面的代码可以这样写:Num=(Num<<1)+(Num<<3)+ch-'0';
        ch=getchar(); //读取下一个字符
    }
    return Num*F; //将读取完毕的字符返回
}
int main()
{
    int a,b;
    a=Read();
    b=Read();
    //读取a和b,等价于cin>>a>>b;
}

fread and fwrite

namespace IO
{
	char buf[1<<15],*fs,*ft;
	inline char getc() { return (ft==fs&&(ft=(fs=buf)+fread(buf,1,1<<15,stdin),ft==fs))?0:*fs++; }
	template<typename T>inline void read(T &x)
	{
		x=0;
		T f=1, ch=getchar();
		while (!isdigit(ch) && ch^'-') ch=getchar();
		if (ch=='-') f=-1, ch=getchar();
		while (isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48), ch=getchar();
		x*=f;
	}

	char Out[1<<24],*fe=Out;
	inline void flush() { fwrite(Out,1,fe-Out,stdout); fe=Out; }
	template<typename T>inline void write(T x,char str)
	{
		if (!x) *fe++=48;
		if (x<0) *fe++='-', x=-x;
		T num=0, ch[20];
		while (x) ch[++num]=x%10+48, x/=10;
		while (num) *fe++=ch[num--];
		*fe++=str;
	}
}

using IO::read;
using IO::write;

Lcentury’s 快读

//灵魂快读
int read()
{
	int a;
	cin>>a;
	return a;
}

你可能感兴趣的:(模板,快读,快写)