快读快写模板
更新日志
2025/05/18:开工。2025/05/31:快读字符串增添对 \r 与 EOF 的判断。
2025/06/22:重构,简化,增添多元素读入。
2025/06/12:支持 C 型字符串直接输出。
简介
就是使用 getchar 和 putchar 优化输入输出。
提供了整数、浮点数、字符串、字符的快读快写。支持一次性读入多个元素。
有些快读快写不保证能优化多少,浮点数的“快写”很幽默,你可以视作简化了输出函数。
记得 #define flt 成你常用的浮点类型,并只会输出这个类型的浮点数。
模板
template<typename Type> inline void read(Type &x){x=0;Type f=1,s=1;char ch=getchar();while(!isdigit(ch)&&~ch){if(ch=='-')f=-1;ch=getchar();}while(isdigit(ch))x=x*10+ch-48,ch=getchar();if(ch=='.'){ch=getchar();while(isdigit(ch))s/=10,x=x+(ch-48)*s,ch=getchar();}x*=f;}
template<typename Type> inline void write(Type x){if(x<0)putchar('-'),x=-x;if(x>9)write(x/10);putchar(x%10+'0');}
inline void read(string &s){s.clear();char ch=getchar();while(isspace(ch))ch=getchar();while(!isspace(ch)&&~ch)s+=ch,ch=getchar();}
inline void read(char &ch){ch=getchar();while(isspace(ch))ch=getchar();}
inline void write(const string &s){for(auto c:s)putchar(c);}
inline void write(const char &ch){putchar(ch);}
inline void write(const flt &x){printf("%.18LF",(long double)x);}
inline void write(const mint &m){write(m.x);}
inline void write(const char *x){while(*x)putchar(*(x++));}
template<typename Type,typename...T> inline void read(Type &x,T&...y){read(x),read(y...);}
template<typename Type> inline void put(const Type &x,char ch='\n'){write(x);if(ch)putchar(ch);}

浙公网安备 33010602011771号