I had read in few articles that the unlocked version of fread and fwrite
tends to crash more often.I tried with both,though my parsing algo was a bit
redundant as compared to sankalp sir's the non unlocked fns were  very
slightly slower.........  <.03s for 10^6 integers.....
On Wed, Apr 20, 2011 at 6:27 PM, sankalp srivastava <
richi.sankalp1...@gmail.com> wrote:

> use this
> #include<cstdio>
> #include<iostream>
>
> char ipos, opos, InpFile[20000000], OutFile[20000000], DIP[20];
> inline int input(int flag=0) {
>
> while(*ipos <= 32) ++ipos;//skips white spaces
>
> if ( flag ) return (*ipos++ - '0'); / For getting Boolean Characters
> */
> int x=0, neg = 0;char c;
> while( true ) {
> c=*ipos++;
> if(c == '-') neg = 1;
> else {
> if (c<=32) return neg?-x:x;
> x=(x<<1)+(x<<3)+c-'0';
> }
> }
> }
> inline void output(int x,int flag) {
> int y,dig=0;
> if(x<0){
> *opos++='-';
> x=-x;}
>
> while (x||!dig) { y=x/10;DIP[dig++]=x-((y << 3) + (y << 1))+'0';x=y;}
> while (dig--) *opos++=DIP[dig];
> *opos++= flag ? '\n' : ' ';
> }
> inline void InitFASTIO() {
> ipos = InpFile; opos = OutFile;
> fread_unlocked(InpFile,20000000,1,stdin);
> }
> inline void FlushFASTIO() {
> fwrite_unlocked(OutFile,opos-OutFile,1,stdout);
> }
>
>
>
> On Apr 20, 8:06 am, abhijith reddy <abhijith200...@gmail.com> wrote:
> > You could read input character by character using getchar_unlocked()
> untill
> > you hit a space or new line or EOF.
> > Alternatively you read the whole input at once using fread_unlocked() and
> > then process it as per your need.
> >
> >
> >
> >
> >
> >
> >
> > On Wed, Apr 20, 2011 at 7:41 AM, shubham <shubh2...@gmail.com> wrote:
> > > Hello Geeks,
> > > Suppose we have a 2-d array arr[1000][1000] capable of storing 10^6
> > > elements in it. Input is supplied one row at a time. Then what is the
> > > best possible way to read this much data in the least amount of time
> > > as scanf() or cin takes a lot of time?
> >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups
> > > "Algorithm Geeks" group.
> > > To post to this group, send email to algogeeks@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > algogeeks+unsubscr...@googlegroups.com.
> > > For more options, visit this group at
> > >http://groups.google.com/group/algogeeks?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
Saurabh Singh
B.Tech (Computer Science)
MNNIT ALLAHABAD

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to