What is this Fast I/O code than printf() & scanf() in c++???

In many solution of problems i have noticed that many users use some kind of code for Fast I/O technique which made their execution a lot faster than usual despite of having same logic??
For e.g.
http://www.codechef.com/viewsolution/244848
above code execution time was 0.09!!
and this my code:
http://www.codechef.com/viewsolution/972910
with execution time of 0.79!!
This is a lot of difference which occurred only due to printf() & scanf() vs. some Fast I/0 Code??

Not 100% sure , but basically the difference is that Printf is a generic function made to recognize various format, data types and to extract that from the input, here it directly reads the stream in the raw form, and you are responsible for extracting the information required. Hence you save a lot of overheads, which add time.

4 Likes

How are we able to save the overheads could u explain it please?I understand that we’re extracting the data in raw form and then extracting the required information but this also is taking time isn’t it?

1 Like

The same thing is discussed over here. Please read it.

why negative input gives positive output if printed as it is suing the fast input methods???

fast IO in C++

      inline void read(int &x){

        x=0;
        register char c=gc();
        for(;c<'0' || c>'9';c=gc());
         for(;c>='0' && c<='9';c=gc())
          x=(x<<3)+(x<<1)+(c-'0');
      }
      inline void write(int x){

         register char buffor[35];
         register int i=0;
         do{
               buffor[i++]=(x%10)+'0';
               x/=10;
            } while(x);
           i--;
            while(i>=0) putchar_unlocked(buffor[i--]);
            putchar_unlocked('\n');
       }