快读快写

int read() {
    register int x = 0,f = 1;register char ch;
    ch = getchar();
    while(ch > '9' || ch < '0'){if(ch == '-') f = -f;ch = getchar();}
    while(ch <= '9' && ch >= '0'){x = x * 10 + ch - 48;ch = getchar();}
    return x * f;
}
void write(int x){
	if(x<0){putchar('-');x=-x;}//若x为负数,输出符号并取其绝对值
	if(x>9){write(x/10);putchar(x%10+'0');}//输出绝对值(采用递归的做法,减少代码量)
	else putchar(x+'0');
	return; 
}

n >= 1e8时,比scanf和printf快一倍左右

参考:浅谈快读快写快读和快写

posted @ 2023-01-29 20:14  f2021yjm  阅读(14)  评论(0编辑  收藏  举报