跳到正文

算法·理论

c++快速读入

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

文章信息

收录
2026年3月4日
更新
2026年3月4日
篇幅
约 1 分钟

版本

  1. v1当前
C++
#include <type_traits>
#include<bits/stdc++.h>
using namespace std;
inline read(const char *category,int _else=0){
	if(*category==*((const char*)"char")) return getchar();
	if(*category==*((const char*)"int")){
		int x=0;
		char c=getchar();
		while('0'<=c&&c<='9')
			x=x*_else+('0'<=c&&c<='9'?c-'0':c-'A'+1);
		return x;
	}
	if(*category==*((const char*)"bool")) return read("int",16)!=0;
	if(*category==*((const char*)"double")){
		double x=read("int",_else);
		int y=0,mine=0;
		char c=getchar();
		while('0'<=c&&c<='9')
			y=y*_else+('0'<=y&&y<='9'?c-'0':c-'A'+1),mine++;
		x+=y*1.0/mine/_else;
	}
}

为’正解’会 TLE 的代码贴上 AC 之符

原文