网上看到段自定义的getInt()来替代cin.nextInt(),不是很明白
自定义的代码 getInt() 在空间开销上只有 nextInt() 的1/30,
然后代码里的"45"、"48"哪里来的?求点拨~
代码如下:
public static BufferedInputStream bis = new BufferedInputStream(System.in);nextInt()
public static int getInt() throws IOException
{
int i;
while ((i = bis.read()) < 45)
;
// if(i==-1)
// return -1;
int temp = 0, mark = 1;
if (i == 45)
{
mark = -1;
i = bis.read();
}
while (i > 47)
{
temp = temp * 10 + i - 48;
i = bis.read();
}
return mark * temp;
}