快速输入输出
功能
对于大量数据进行快速输入输出。
思路
利用getchar()代替scanf()输入整数,利用putchar()代替printf()输出整数。
模板
非负整数输入
/**
* @param x: the input number
* @other: x >= 0;
*/
void FR(int& x) {
x = 0;
char ch = getchar();
for (; ch < '0' || ch > '9'; ch = getchar());
for (; ch >= '0' && ch <= '9'; ch = getchar()) {
x = 10*x + ch-'0';
}
}
非负整数输出
char f[100]; // the digits of the output number
/**
* @param x: the output number
* @other: x >= 0;
*/
void FW(const int& x) {
int tmp = x;
int s = 0;
while (tmp > 0) {
f[s++] = tmp%10 + '0';
tmp /= 10;
}
while (s > 0) putchar(f[--s]);
}
整数输入
/**
* @param x: the input number
*/
void FR(
算法:高效IO模板

本文介绍了如何在处理大量数据时实现快速的输入输出操作。通过使用特定的输入输出技巧,如利用快速读写方法,可以显著提升算法的运行效率。文章提供了非负整数和整数的输入输出模板,帮助程序员在解决编程问题时提高性能。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



