Fastinputoutputfunction

Can we use fast input output functions when the input and output are having negative value?

Yes you need to take care that if - sign appear you do not skip processing it!

@va1ts7_100 try this

#define getcx getchar_unlocked
inline long long in()
{
   long long n=0;
   long long ch=getcx();long long sign=1;
   while( ch < '0' || ch > '9' ){if(ch=='-')sign=-1; ch=getcx();}
 
   while(  ch >= '0' && ch <= '9' )
           n = (n<<3)+(n<<1) + ch-'0', ch=getcx();
   return n*sign;
}

See this code - http://ideone.com/yrixKp

Hope it helps.

2 Likes

@anh1l1ator what changes should i make in my code…? i can’t find it by myself.help me.

#define gc getchar_unlocked
#define pc putchar_unlocked

inline void fastRead(int *b)
{
register char c=0;
while (c<33) c=gc();
*b=0;
while (c>33)
{
*b=b10+c-‘0’;
c=gc();
}
}

inline void fastWrite(int b)
{
char snum[20];
int i=0;
do
{
snum[i++]=b%10+48;
b=b/10;
}while(b!=0);
i=i-1;
while(i>=0)
pc(snum[i–]);
pc(’\n’);
}

Well @rjohari explains it pretty well!

thanks @rjohari:slight_smile: ur code is really helpful… !

1 Like

u r welcome @va1ts7_100 :slight_smile: