Skip to content

Instantly share code, notes, and snippets.

@Sorebit
Last active December 4, 2016 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sorebit/1f6ef985f2f628bd22411f70cb7dd49f to your computer and use it in GitHub Desktop.
Save Sorebit/1f6ef985f2f628bd22411f70cb7dd49f to your computer and use it in GitHub Desktop.
Fast I/O for C++
#include <cstdio>
#define abs(a) ((a < 0) ? -(a) : (a))
template <class T>
void print(T a)
{
if(a == 0)
putchar_unlocked('0');
if(a < 0)
putchar('-');
a = abs(a);
char b[10];
int i = 0;
for (; i < 10 && a; i++)
{
b[i] = a % 10;
a /= 10;
}
for (i--; i >= 0; i--)
putchar_unlocked(b[i] + '0');
}
template <class T>
void read(T & a)
{
a = 0;
bool u = false;
char c = 0;
while (c < '0' || c > '9')
{
c = getchar_unlocked();
if(c == '-')
u = true;
}
do
{
a *= 10;
a += c - '0';
} while ((c = getchar_unlocked()) >= '0' && c <= '9');
if(u)
a = -a;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment