你还在为快读不支持各种各样的类型而烦恼吗?
  • 板块灌水区
  • 楼主FOF_FOF_QBI
  • 当前回复8
  • 已保存回复8
  • 发布时间2024/7/30 18:53
  • 上次更新2024/7/30 19:49:48
查看原帖
你还在为快读不支持各种各样的类型而烦恼吗?
738332
FOF_FOF_QBI楼主2024/7/30 18:53

是的,我们的快读快写支持int和char类型,您只需要使用一个read和write即可

以下是代码


#include <cstdio>
#include <cctype>
#include <string>

void read(char &c) {
	c = getchar();
	while (isspace(c)) {
		c = getchar();
	}
}

void read(std::string &s) {
	s.clear();
	char c = getchar();
	while (isspace(c)) {
		c = getchar();
	}
	while (!isspace(c) && c != EOF) {
		s += c;
		c = getchar();
	}
}

template <typename T>
void read(T &x) {
	char ch;
	bool neg = false;
	x = 0;
	while ((ch = getchar()) && !isdigit(ch)) {
		if (ch == '-') {
			neg = true;
		}
	}
	do {
		x = x * 10 + ch - '0';
	} while ((ch = getchar()) && isdigit(ch));
	if (neg) {
		x = -x;
	}
}
void write(char c) {
	putchar(c);
}

void write(const std::string &s) {
	for (char c : s) {
		putchar(c);
	}
}

template <typename T>
void write(T x) {
	if (x < 0) {
		putchar('-');
		x = -x;
	}
	char buffer[20];
	int len = 0;
	do {
		buffer[len++] = (x % 10) + '0';
		x /= 10;
	} while (x);
	while (len--) {
		putchar(buffer[len]);
	}
//	putchar('\n');
}

文件名:fastio.h

如何将头文件添加进你的g++编译器里?(仅限Windows)

首先,随便打一个

#include<iostream>

随后,Ctrl+左键(鼠标)(Dev-CPP及其衍生版本皆可)点击一下文件头(不出意料地,头文件下会出现下划线,随后打开文件头)

文件头打开后,Dev-C++ 5.11按Ctrl+B进到文件所在的文件夹内,小熊猫C++右键代码编辑空白处,选择"打开所在的文件夹"

在IDE中新建文件,输入你文件头内包含的代码,找到你刚才打开的头文件所在的文件夹路径(最好是复制过来)保存

重启IDE,不出意料地,代码中就可以使用你的头文件了

2024/7/30 18:53
加载中...