为什么读入优化会快
因为getchar比scanf快……
模板代码(也可以把int改为long long,若改为浮点型,还要特判一下小数点):
int read()
{
char ch;
int data = 0;
int f = 1;
while(ch <'0'||ch >'9')
{
ch = getchar();
if(ch == '-')
f = -1;
}
do{
data = data*10 + ch-'0';
ch = getchar();
}while(ch >='0'&&ch <='9');
return data*f;
}
THE END
By Peacefuldoge

本文介绍了一种使用getchar进行快速输入的方法,相比于scanf,getchar能够显著提高读入速度。文中提供了一个模板代码,演示了如何用getchar读取整数并处理负号的情况。此方法适用于需要高效输入处理的编程竞赛或高性能应用。
4350

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



