Skip to content

Instantly share code, notes, and snippets.

@shobhit6993
Last active September 13, 2016 02:30
Show Gist options
  • Save shobhit6993/6740609 to your computer and use it in GitHub Desktop.
Save shobhit6993/6740609 to your computer and use it in GitHub Desktop.
This easy-to-understand and easy-to-code snippet comes handy while taking fast integer (negative as well as positive) inputs in coding competitions and online judges like SPOJ, Codechef etc. The getchar_unlocked() function might not work on some judges like CodeForces, where getchar() can be used instead. Slight modification can be done to make …
inline void fastRead(int n,std::vector<int> &input)
{
for (int i = 0; i < n; ++i)
{
int sign=1;
register char c=0;
while(c<'0' || c>'9')
{
c=getchar_unlocked();
if (c=='-')
{
sign=-1; c=getchar_unlocked();
}
else
sign=1;
}
int x=0;
do
{
x=(x<<3)+(x<<1)+c-'0';
} while((c=getchar_unlocked())>='0' && c<='9');
input.push_back(x*sign);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment