跳到正文

算法·理论

读入输出优化

huanshenxxn约 1 分钟
原文
文章信息与版本

文章信息

发布
2026年11月2日
收录
2026年11月26日
更新
2026年11月26日
篇幅
约 1 分钟

版本

  1. v1当前

扎啤的读入输出优化ovo

C++
void read(int &x) {
	bool neg=false;
	x=0;
	char ch=0;
	while (ch<'0'||ch>'9') {if (ch=='-') neg=true;ch=getchar();}
	if (neg) {while (ch>='0'&&ch<='9') {x=x*10+('0'-ch);ch=getchar();}
	}else {while (ch>='0'&&ch<='9') {x=x*10+(ch-'0');ch=getchar();}}
}
void write(int x) {
	bool neg=false;
	if (x<0) {neg=true;putchar('-');}
	static int sta[40];
	int top=0;
	do {sta[top++]=x%10;x/=10;}while (x);
	if (neg) while (top) putchar('0'-sta[--top]);
	else while (top) putchar('0'+sta[--top]);
}
原文