Reading input using getchar_unlocked ()

I found out that using getchar_unlockedis a quick way to read input. I saw that the code was read in many places, but could not understand. Can someone help me figure out how to read using getchar_unlocked? Thank you in advance.

void scanint(int &x)
{
 register int c = getchar_unlocked();
 x = 0;
 for(;(c<48 || c>57);c = getchar_unlocked())
  ;
 for(;c>47 && c<58;c = getchar_unlocked()) 
 {
   x = (x<<1) + (x<<3) + c - 48;
 }
}

I have seen many other codes. I do not particularly understand the purpose of shifting the number. Any help in this regard is appreciated.

+4
source share
3 answers

getch_lock . . for , . for char,  n=n*10+c
C Ascii, 48, .. Ascii- '0'. , . n*10=n*(8+2)=n*8+n*2=n<<3+n<<1

+4

getchar_unlocked() getchar(), , .

, , .

+1

, getchar_unlocked(). .

- - , , "", .

You have included a function that reads an integer with getchar_fast()and is written in a rather horrible style. This, of course, does not seem to be part of the solution to anything in particular. It is also completely broken when processing a pointer variable x.

In short, your question is not very clear.

0
source

All Articles