shock. 99.9% of Oier don't know. Using this method, the violence immediately changed the scale.
Recently learned a new function fread, you can read the entire block from the file into the information, fast. Based on this function, we can write a new GetChar ():
Inline Char GC () {
static char buf[100000],*p1=buf,*p2=buf;
Return p1==p2&& (p2= (p1=buf) +fread (Buf,1,100000,stdin), P1==P2)? eof:*p1++;
}
Fread's 4 parameters represent where to start saving, a number of bytes (char is 1), and want to read a few, input files. After execution, it returns a few successful reads.
The BUF array is a note of the read information. The p1p2 points to the head and tail in the current buf, respectively. If P1==P2 explains that you need to fread a whole block again.
Use it to write read excellent effect is very good, the input stream is very large when compared with GetChar () read more than twice times faster.
The complexity of the scale is relatively tight, write a metaphysical violence plus reading may be AC.
But be sure to note that this cannot be mixed with scanf. SCANF can be used before the first tuning of GC ().