1. 程式人生 > >讀入優化&&輸出優化

讀入優化&&輸出優化

#include<cstdio>
int isdigit[300];

void read(int &x)
{
	int f = 1; x = 0; char s = getchar();
	while(!isdigit[s]) {if(x == '-') f = -1; s = getchar();}
	while(isdigit[s]) {x = x*10 + s-'0'; s = getchar();}
	x *= f;
}

void print(int x)
{
	if(x < 0) {putchar('-'); x = -x;}
	if(x > 9) print(x / 10);
	putchar(x % 10 + '0');
}

int main()
{
	for(int i = '0'; i <= '9'; i++) isdigit[i] = 1;
}